C# Console Library app.config 连接字符串问题
我创建了一个本地数据库:
<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>
该项目的名称是“DataAccessLayer”(类库项目)。 该解决方案由另一个类库和一个 Web 应用程序组成。
我已将解决方案发送给我的朋友,让他看一下我的代码...他安装了 VS2010 和 SQL Server Express(和我一样)。 但当他尝试登录时,出现以下错误:
“与 SQL Server 建立连接时发生网络相关或特定于实例的错误。找不到服务器或无法访问服务器。请验证实例名称是否为正确,并且 SQL Server 配置为允许远程连接(提供程序:SQL 网络接口,错误:26 - 指定服务器/实例错误)”
我们尝试修复此问题 4 小时,当然使用 google - 无结果。
有什么想法吗?
谢谢!!!
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!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在他的盒子上,
(local)
将不存在。连接字符串需要在他的盒子上指定你的机器。On his box,
(local)
won't exist. The connection string needs to specify your machine on his box.他把文件放在bin目录下了吗?
Does he put the file at the bin directory ?
如果您的 SQLExpress 在开发计算机上安装良好,只需尝试 localhost\SQLExpress 而不是 (local)\SQLExpress 并验证 SQLExpress 服务是否正在运行
If you SQLExpress is well installed on the development machine, just try localhost\SQLExpress instead of (local)\SQLExpress and verify that SQLExpress service is running
最后,我们设法找到了解决方案:
'Data Source=.;'而不是“数据源=(本地)\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...