3
votes

I have a C# app that connects to a SQL Server .mdf database file that sits in the root of my apps directory. The app is distributed to other users in a company. They are receiving the following 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. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Not all users are getting this error. I am assuming it is a security error. Below is my connection string. Any idea what is causing this issue and how can I resolve it?

<add name="EditorConnectionString" 
     connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Resources.mdf;Integrated Security=True;User Instance=True;Persist Security Info=true;Connection Timeout=130" 
     providerName="System.Data.SqlClient" />
1
are you accessing mdf file from remote machine?Sudhakar Tillapudi
Read the error message. Is SQL Server running on the local machine?SLaks
the app connects to the mdf database which is in the same folder as the app. So yes it is running on the local machine.PhillyNJ
@marc_s I am not sure. Does Sql Express need to be running on the local machine?PhillyNJ
Yes, it must be the Express edition, and it must run locally on that machinemarc_s

1 Answers

3
votes

If you're using the AttachDbFileName=... approach in your connection string, the SQL Server used for this MUST BE the Express edition.

Also, since the connection string contains .\SQLEXPRESS as its Data Source= value, that SQL Server Express instance must be running locally on that particular machine (that's significance of the . in the Data Source= value)