gofor.net
gofor.net

Reputation: 4298

sql connection string issue

I want to connect to a remote database (SQL Server 2008) through code using a connection string. 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.

But whenever I am trying using code I am getting the exception like::

[DBNETLIB][ConnectionOpen (Invalid Instance()).]Invalid connection.

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.

Upvotes: 0

Views: 7963

Answers (1)

marc_s
marc_s

Reputation: 755491

You don't show the C# code you're using to connect - but I think the problem is the provider. If ever possible - use the native SQL client interface from the System.Data.SqlClient assembly to connect to 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.

Upvotes: 6

Related Questions