简体   繁体   中英

C# Console Library app.config connection string problem

I've created a local DB:

    <connectionStrings>
    <add name="DataAccessLayer.Properties.Settings.TestDBConnectionString"
        connectionString="Data Source=(local)\SQLEXPRESS;AttachDbFilename=|DataDirectory|\bin\TestDB.mdf;Integrated Security=True;User Instance=True"
        providerName="System.Data.SqlClient" />
</connectionStrings>

The project's name is "DataAccessLayer" (class library project). The solution consits of another class library and a web application.

I've sent the solution to my friend to take a look at my code... He has VS2010 installed with SQL Server Express (exactly like me). But when he tries to do a login, he gets the following 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: 26 - Error Locating Server/Instance Specified)"

We are trying to fix this like for 4 hours and using google of course - no result.

Any ideas??

Thanks!!!

On his box, (local) won't exist. The connection string needs to specify your machine on his box.

他是否将文件放在bin目录中?

如果您在开发计算机上正确安装了SQLExpress,则只需尝试使用localhost \\ SQLExpress而不是(local)\\ SQLExpress并验证SQLExpress服务正在运行

Finally, we managed to find a solution:

'Data Source=.;' instead of 'Data Source=(local)\\SQLEXPRESS;' and

'User Instance=False' instead of 'User Instance=True'

I hope this will be useful for someone in the future...

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