我支持一个旧的 vb.net 程序,其连接的数据库已从 SQL Server 2005 移至 SQL Server 2008。SQL Server 2008 上是否有一个设置允许 ODBC 连接访问数据库但不允许 VB .NET 以编程方式连接到它?
我在应用程序中不断收到的错误是:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)
但是,当我创建到sql server实例的系统dsn并通过VS2005的工具>>连接到数据库时,我可以连接到它。
这是我用来连接的代码:
dim strC as string
strC = "data source=bob; database=subscribers; user id=bobuser; password=passme"
dim connection as New SqlClient.SqlConnection(strC)
try
connection.open()
catch ex as Exception
msgbox(ex.message)
end try
connection.Close()
最佳答案
没有这样的设置,但它是可能的,因为:您可以通过 ODBC 访问您的服务器,因为使用 ODBC DSN 会创建一种到服务器的本地桥。尝试使用客户端计算机上的 SqlClient 库从 VB.NET 代码连接到服务器需要您的 Sql Server 接受远程连接...
检查这个MSDN article寻求帮助。
简而言之:
- 您需要将 Sql Server 设置为允许远程连接
- 您需要确保您的防火墙没有阻止 Sql Server 的端口
- 确保 TCP/IP 已作为通信启用。 Sql Server 机制
关于vb.net - 为什么我可以通过odbc连接到sql server 2008,但不能通过vb.net代码连接到sql server 2008?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4619140/