I'm supporting an old vb.net program whose database it connected to was moved from SQL Server 2005 to SQL Server 2008. Is there a setting on SQL Server 2008 which will allow ODBC connections to access the database but not allow VB.NET to connect to it programmatically?
the error i keep receiving in the app is:
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)
however I can connect to it when I create a system dsn to the sql server instance and through VS2005's Tools >> Connect to Database.
Here is the code I'm using to connect:
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()
There is no such setting but it is possible because: You are able to access your sever via ODBC because using an ODBC DSN creates a sort of local bridge to the server. Trying to connect to the server from VB.NET code with the SqlClient library from a client machine requires your Sql Server to accept remote connections...
Check this MSDN article for help.
In brief:
- You need to set Sql Server to allow remote connections
- You need to make sure your firewall isn't blocking Sql Server's port(s)
- Make sure TCP/IP is enabled as a comm. mechanism for Sql Server
Start > Run > "CLICONFG" (No quotes)
In the SQL Server Client Network Utility, enable Named Pipes over TCP/IP
精彩评论