如何解决system.data.sqlclient.sqlexception(0x80131904)错误 [英] How to solve the system.data.sqlclient.sqlexception (0x80131904) error

查看:207
本文介绍了如何解决system.data.sqlclient.sqlexception(0x80131904)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#和SQL Server 2008 R2创建了一个可以在我的PC上完美运行的应用程序.我的连接字符串是:

I've created an application that works perfectly on my PC using C# and SQL Server 2008 R2. My connection string is:

connectionString="Data Source=KELVIN-PC;Initial Catalog=LMS;User ID=sa;Password=temperament"

但是我已经发布了它,并将其安装在另一台PC上.我还将 LMS.bak 文件复制到PC上,并在 MS SQL Server 2008 R2 上还原了数据库.但是每当它必须连接到另一台计算机上的数据库时,就会出现以下错误:

But I have published it and installed it on another PC. I also copied the LMS.bak file to the PC and restored the database on it MS SQL Server 2008 R2. But whenever it has to connect to the database on the other machine it gives the error below:

System.Data.SqlClient.SqlException(0x80131904):建立与SQL Server的连接时,发生了与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称正确,并且已将SQL Server配置为允许远程连接.(提供者:命名管道提供程序,错误:40-无法打开与SQL Server的连接).....

System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while extablishing 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: Named pipes Provider, error:40 - Could not open a connection to SQL Server).....

我花了数小时在互联网上进行搜索,但是大多数已回答的问题与我自己的问题都没有太大的区别,而且我尝试过的一些建议并没有真正起作用.

I've spent hours searching through the internet but most answered problems have a little difference from my own and some suggestions I have tried didn't really work.

推荐答案

您还需要更改连接字符串的 DataSource . KELVIN-PC 是您的本地计算机的名称,并且sql server在默认实例上运行.

You also need to change the DataSource of the connection string. KELVIN-PC is the name of your local machine and the sql server is running on the default instance.

如果确定服务器正在作为默认实例运行,则始终可以在数据源中使用.,例如.

If you are sure the the server is running as the default instance, you can always use . in the DataSource, eg.

connectionString="Data Source=.;Initial Catalog=LMS;User ID=sa;Password=temperament"

否则,您需要指定服务器实例的名称,

otherwise, you need to specify the name of the instance of the server,

connectionString="Data Source=.\INSTANCENAME;Initial Catalog=LMS;User ID=sa;Password=temperament"

这篇关于如何解决system.data.sqlclient.sqlexception(0x80131904)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆