How many types of connection strings in Sql Server?

A connection string provides the information that a provider needs to communicate with a particular database. The Connection String includes parameters such as the name of the driver, Server name and Database name , as well as security information such as user name and password.
An ADO.NET Data Provider is a class that can communicate with a specific type of database or data store. Usually Data Providers use a connection string containing a collection of parameters to establish the connection with the database through applications. The .NET Framework provides mainly three data providers, they are-

  • OLEDB
  • ODBC

From the following section you can find different types of providers and its connection strings in detail.

Microsoft SQL Server

.NET DataProvider - Standard Connection
using System.Data.SqlClient;
ConnectionString = "Data Source=servername;Initial Catalog=databasename;User id=uasername;Password=password";
SqlConnection connection ;
connection = new SqlConnection(ConnectionString);
connection.Open();

.NET DataProvider - Trusted Connection

using System.Data.SqlClient;
ConnectionString = "Data Source=servername;Initial Catalog=databasebame;Integrated Security=SSPI";
SqlConnection connection ;
connection = new SqlConnection(ConnectionString);
connection.Open();

.NET DataProvider - using IP Address

using System.Data.SqlClient;
ConnectionString = "Network Library=DBMSSOCN;Data Source=your IP Address,1433;Initial Catalog=datadasename;User Id=username;Password=password";
SqlConnection connection ;
connection = new SqlConnection(ConnectionString);
connection.Open();

OleDb - Standard Connection

using System.Data.OleDb;
ConnectionString = "Driver=SQLOLEDB;Data Source=servername;Initial Catalog=databasename;User id=username;Password=password";
OleDbConnection connection ;
connection = new OleDbConnection(ConnectionString);
connection.Open();

OleDb - Trusted Connection

using System.Data.OleDb;
ConnectionString = "Driver=SQLOLEDB;Data Source=servername;Initial Catalog=databasename;Integrated Security=SSPI";
OleDbConnection connection ;
connection = new OleDbConnection(ConnectionString);
connection.Open();

ODBC DSN

using System.Data.Odbc;
ConnectionString = "Dsn=yourdsnname;Uid=username;Pwd=password";
OdbcConnection  connection ;
connection = new OdbcConnection(ConnectionString);
connection.Open();

ODBC - Standard Connection

using System.Data.Odbc;
ConnectionString = "Driver={SQL Server};Server=servername;DataBase=databasename;Uid=username;Pwd=password";
OdbcConnection  connection ;
connection = new OdbcConnection(ConnectionString);
connection.Open();

ODBC - Trusted Connection

using System.Data.Odbc;
ConnectionString = "Driver={SQL Server};Server=ServerName;DataBase=DataBaseName;Trusted_Connection=Yes";
OdbcConnection  connection ;
connection = new OdbcConnection(ConnectionString);
connection.Open();

Need Help? Contact Us.

Log in

*
*

Forgot password?

*

New User

*
*
*
*