Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SqlException (0x80131904) connecting to mdf database

Tags:

c#

sql-server

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" />
like image 528
PhillyNJ Avatar asked Jan 01 '26 20:01

PhillyNJ


1 Answers

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)

like image 114
marc_s Avatar answered Jan 03 '26 09:01

marc_s



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!