Last post Jul 18, 2016 06:21 AM by Yohann Lu
Jul 17, 2016 12:02 PM|Ciwan|LINK
Yesterday I had to format my PC and reinstall all my applications. Though this time instead of SQL Server 2013, I went for SQL Server 2016 Developer edition.
I fired up Visual Studio 2015 and opened a solution I had in my GitHub account. I went to the package manager console and ran the Update-Database command, but now I get an error.
System.Data.SqlClient.SqlException (0x80131904): 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.
Before this use to run the code that would create my database and seed it with data.
I have checked the Kaspersky Firewall and ensured that all SQL related stuff are set to 'Allow'. I also checked the SQL Server itself and ensured that remote connections were permitted.
Why is this happening and how do I fix it? In package manager console, when I run the following command 'SQLLocalDb info' I get MSSQLLocalDB. The connection string I have defined is the following:
<add name="DbContext" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\BBContext.mdf;Initial Catalog=BBContext;Integrated Security=True" providerName="System.Data.SqlClient" />
Any help would be greatly appreciated.
Jul 17, 2016 06:32 PM|maherjendoubi|LINK
Please use this connectionString :
Jul 18, 2016 06:21 AM|Yohann Lu|LINK
From your error message, I suggest you can check the following steps.
1. Go to Sql Server Configuration management->SQL Server network config->protocols for 'servername' and check TCP/IP is enabled.
2. Open SSMS in a run, and check you are able to login to the server using the specfied username/password and/or using windows authentication.
3: Make sure your connection string is correct. Your connection string is connected to Visual Studio 2012 local DB.
If you are sure the server is running as the default instance, you can always use . in the DataSource, eg.
connectionString="Data Source=.;Initial Catalog=LMS;User ID=sa;Password=temperament"
otherwise, you need to specify the name of the instance of the server,
connectionString="Data Source=.\INSTANCENAME;Initial Catalog=LMS;User ID=sa;Password=temperament"