[英]sql connection string issue
I want to connect to a remote database (SQL Server 2008) through code using a connection string. 我想使用连接字符串通过代码连接到远程数据库(SQL Server 2008)。 But I am not be able to connect to it. 但是我无法连接到它。 But I can connect the database using the SQL Server Management Studio successfully, using SQL Server authentication. 但是我可以使用SQL Server身份验证使用SQL Server Management Studio成功连接数据库。
But whenever I am trying using code I am getting the exception like:: 但是,每当我尝试使用代码时,都会出现类似如下的异常:
[DBNETLIB][ConnectionOpen (Invalid Instance()).]Invalid connection. [DBNETLIB] [ConnectionOpen(无效的Instance())。]无效的连接。
My connection string is like this :: 我的连接字符串是这样的:
Data Source=192.x.x.x;Initial Catalog=mydbName;User ID=user;Password=passw;provider=SQLOLEDB
Can anybody help me out. 谁能帮我。
thanks in advance. 提前致谢。
You don't show the C# code you're using to connect - but I think the problem is the provider. 您没有显示用于连接的C#代码-但我认为问题出在提供商。 If ever possible - use the native SQL client interface from the System.Data.SqlClient
assembly to connect to SQL Server. 如果可能,请使用System.Data.SqlClient
程序System.Data.SqlClient
的本机 SQL客户端接口连接到SQL Server。
Can you try this connection string instead: 您可以改用以下连接字符串吗:
Data Source=192.x.x.x;Initial Catalog=mydbName;User ID=user;Password=passw;
In your config: 在您的配置中:
<configuration>
<connectionStrings>
<add name="MyConnStr"
connectionString="Data Source=192.x.x.x;Initial Catalog=mydbName;User ID=user;Password=passw;" />
</connectionStrings>
</configuration>
And then use this code snippet: 然后使用以下代码片段:
string connectionString = ConfigurationManager.ConnectionStrings["MyConnStr"].ConnectionString;
using(SqlConnection conn = new SqlConnection(connectionString))
{
....
}
See the Connection Strings web site for tons of examples of valid connection strings and what all those options mean. 请参阅“ 连接字符串”网站,以获取大量有效连接字符串的示例以及所有这些选项的含义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.