I am getting this connection error when I open the web application
This is my connection string
<add name="DBCS" connectionString="Data Source=ABC-DEF;Initial Catalog=DB; Integrated Security=True;MultipleActiveResultSets=true" providerName="System.Data.SqlClient"/> Also to add, the site was working fine, this error is sudden. I have tried restarting the sql-server services and also set static tcp port. Still does not work. Where is the error?
6 Answers
Try one of the following
- make sure that server and client use the same network protocol (enable TCP/IP).
- Enable the service SQL Browser from your server.
- Enable 'Allow remote connections' setting in the server.
- check your server/workstation firewall so it's not blocking anything. Make sure you can access it remotely.
I have had same issue so wanted to share this for anyone who may come across this post in the future like I have. In my case the SQL server service would look like it is running fine but when I would try and restart the service it would hang and not be fully stopped or started and would not budge even after restarting the computer.
I resolved the issue by opening Task Manager (ctrl+shift+esc) and ending the process with the name "SQL Server Windows NT - 64 Bit". I could then restart the SQL server service and everything was fine again - no more error in the web application.
Change you connect string according to the below code, where data source=DESKTOP-6E4R4GB is your SQL server name and initial catalog=Referral2Cash is your db name.
<add name="Entities" connectionString="metadata=res://*/EDMX.Model1.csdl|res://*/EDMX.Model1.ssdl|res://*/EDMX.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=DESKTOP-6E4R4GB;initial catalog=Referral2Cash;integrated security=True;MultipleActiveResultSets=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> I resolved the issue by opening Task Manager CTRL+Shift+Esc and ending the process with the name "SQL Server Windows NT - 64 Bit". I could then restart the SQL server service and everything was fine again - no more error in the web application. Then run => services.msc => start SQL Server (SQLEXPRESS)

I got this same error when using SQL Express, which I resolved by noticing that I had incorrectly specified the port in the data source section of the connection string. In the connection string, I had data source=.\SQLEXPRESS,1433; when the port number should actually have been 1443. This was after enabling TCP/IP over port 1443, as detailed by this guide.
Go to sql server management studio:
- Left pane you see server name.
- Right click and select Property.
- Popup will show server detail.
- Check name property like (your_server_name\MSSQLSERVER2016) your connection string will be like
<add name="DBCS" connectionString="Data Source=ABC-DEF\MSSQLSERVER2016;Initial Catalog=DB; Integrated Security=True;MultipleActiveResultSets=true" providerName="System.Data.SqlClient"/> OR
<add name="DBCS" connectionString="Data Source=.\MSSQLSERVER2016;Initial Catalog=DB; Integrated Security=True;MultipleActiveResultSets=true" providerName="System.Data.SqlClient"/>