简体   繁体   中英

C# Update Connection String Visual Studio

I am having some connectivity issues with Visual Studio and SQL Server .

This is the connections string in my web.config file;

 <connectionStrings>
    <add name="WintipToysConnectionString" connectionString="Data 
Source=localhost\sqlexpress;Initial Catalog=WINGTIPTOYS;Integrated 
Security=True" providerName="System.Data.SqlClient" /> 
  </connectionStrings>

According to my DB connection string found in Visual Studio , my connection string is;

    Data Source=localhost\sqlexpress;Initial Catalog=WINGTIPTOYS;Integrated Security=True

Which seems to add up - but, I get this error when my program hits a certain line;

System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.

I am actually following the WingTipToys tutorial on the Microsoft website and I am struggling to get it to use the Database I attached to SSMS .

I can write queries inside VS which works fine. So I don't really understand why my program is having this error when running?

Thanks.

Admittedly haven't used SQLExpress in a looong time. It looks like the syntax you're using is for an "instance" - which is pointed out in the error message:

...Cannot create an automatic instance...

What you have does look like server\\instance conn string syntax...

Connect to the "default" instance of SQL Express like so: Data Source=.\\\\SQLExpress

Refer to this:

Hth...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM