简体   繁体   中英

SqlException (0x80131904) connecting to mdf database

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" />

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM