I am really suck with connecting my app to a database. I am trying to connect to a database using (localdb)\MSSQLLocalDB in the connection string and I get this error:
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 Can connect to the sql server from SSMS using (localdb)\MSSQLLocalDB
So to test things I changed my datasource to the named pipe of my instance, and I can connect to the db from (my app) web config and SSMS. Only issue with that is that the instance stops after inactivity and when I restart the instance (manually), the named pipe is changed.
Can anyone please help me resolve the issue of not being able to connect using localdb?
Connection strings I am using:
Working:
<add name="constr" connectionString="Data Source=np:\\.\pipe\LOCALDB#FF072C16\tsql\query;Initial Catalog=hands; Integrated Security=True" providerName="System.Data.SqlClient" />
Doesn't work:
<add name="constr" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=hands; Integrated Security=True" providerName="System.Data.SqlClient" />
After further investigation I found these errors in the Application even viewer
Which led me to find this article that solved the issue.
Mainly I had to do these changes:
https://blogs.msdn.microsoft.com/sqlexpress/2011/12/08/using-localdb-with-full-iis-part-1-user-profile/
https://blogs.msdn.microsoft.com/sqlexpress/2011/12/08/using-localdb-with-full-iis-part-2-instance-ownership/