I have moved a project that used to work fine but now it cannot acces my database anymore. I use Entity Framework and have connected to the database in SQL Server 2012 successfully. Here is what my connection string looks like :
<connectionStrings>
<add name="PrincipalServerContext"
connectionString="Data Source=ServerName\SQLEXPRESS;Initial Catalog=PrincipalServerDB;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
When I launch the website, after authentication I retrieve data, but it throws the exception
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
I believe it might have to do with several things but am not sure, and don't know how to fix them :
- User permissions in SQL Server
- Connection strings could be wrong but I checked and re checked a hundred times
Could not make it work like this, and the exception is throw on Linq queries to access DB.
EDIT I did try to publish the web site to test, and have a second connection string :
<connectionStrings>
<add name="PrincipalServerContext_DatabasePublish"
connectionString="Data Source=ServerName\SQLEXPRESS;Initial Catalog=PrincipalServerDB;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Though I'm just trying to debug on the new computer I set up the project, if I remove this line, I have an exception. So maybe my program is searching for this DB and finds nothing?
System.InvalidOperationException cannot find PrincipalServerContext_DatabasePublish connection string
(I translate from french)