All Sample Connection String for All database using C#.Net and VB.Net

Connection string for all database.


Here you can find all connection string for all database using C#.Net and VB.Net

Microsoft SQL Server .NET Data Provider (NameSpace : System.Data.SqlClient)


The Microsoft SQL Server .NET Data Provide allows you to connect to a Microsoft SQL Server databases.
Using C#:

using System.Data.SqlClient;
...
SqlConnection SQLConn = new SqlConnection();
SQLConn.ConnectionString = "Data Source=(local);Initial Catalog=myDatabaseName;User ID=myUsername;"Password=myPassword" ;
SQLConn.Open();
...
SQLConn.Close();

Note : If you open the connection, then close the connection. Otherwise the connection does not go back into the connection pool. The SqlDataAdapter will open and close the connection for you when calling it's Fill or Update methods. However if the connection is already open, the SqlDataAdapter will leave it open.
Using VB.NET:

Imports System.Data.SqlClient
...
Dim SQLConn As SqlConnection = New SqlConnection()
SQLConn.ConnectionString = "Data Source=(local);Initial Catalog=myDatabaseName;"User ID=myUsername;Password=myPassword"
SQLConn.Open()
...
SQLConn.Close()

If connect to a remote server (via IP address):

SQLConn.ConnectionString = _
"Network Library=DBMSSOCN;" Data Source=xxx.xxx.xxx.xxx,1433;Initial Catalog=myDatabaseName;User ID=myUsername;Password=myPassword"
SQLConn.Open()
...
SQLConn.Close()

ODBC .NET Data Provider (NameSpace : System.Data.Odbc)


The Open Database Connectivity (ODBC) .NET Data Provider provides access to database.

For SQL Server ODBC Driver


USING C#.NET


Using System.Data.Odbc ;
...
OdbcConnection ODBCConnection;
string ConnString = "Driver={SQL Server};Server=MySQLServerName;Database=MyDatabaseName;Uid=MyUsername;Pwd=MyPassword" ;
ODBCConnection = New Odbc.OdbcConnection(ConnString) ;
ODBCConnection.Open() ;
...
ODBCConnection.Close() ;

USING VB.NET

Imports System.Data.Odbc
...
Dim ODBCConnection As OdbcConnection
Dim ConnString As String = "Driver={SQL Server};Server=MySQLServerName;Database=MyDatabaseName;Uid=MyUsername;Pwd=MyPassword"
ODBCConnection = New Odbc.OdbcConnection(ConnString)
ODBCConnection.Open()
...
ODBCConnection.Close()

For Oracle ODBC Driver


USING C#.NET


Using System.Data.Odbc ;
...
OdbcConnection ODBCConnection;
string ConnString = "Driver={ Microsoft ODBC for Oracle };Server= OracleServer.world;Database=MyDatabaseName;Uid=MyUsername;Pwd=MyPassword" ;
ODBCConnection = New Odbc.OdbcConnection(ConnString) ;
ODBCConnection.Open() ;
...
ODBCConnection.Close() ;

USING VB.NET

Imports System.Data.Odbc
...
Dim ODBCConnection As OdbcConnection
Dim ConnString As String = "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=myUsername;Pwd=myPassword"
ODBCConnection = New Odbc.OdbcConnection(ConnString)
ODBCConnection.Open()
...
ODBCConnection.Close()

For Access (JET) ODBC Driver


USING C#.NET


using System.Data.Odbc ;
...
OdbcConnection ODBCConnection;
string ConnString ="Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\somepath\mydb.mdb;";
ODBCConnection = New Odbc.OdbcConnection(ConnString) ;
ODBCConnection.Open() ;
...
ODBCConnection.Close() ;

USING VB.NET

Imports System.Data.Odbc
...
Dim ODBCConnection As OdbcConnection
Dim ConnString As String ="Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\somepath\mydb.mdb;"
ODBCConnection = New Odbc.OdbcConnection(ConnString)
ODBCConnection.Open()
...
ODBCConnection.Close()

For Sybase System 11 ODBC Driver


USING VB.NET


Imports System.Data.Odbc
...
Dim ODBCConnection As OdbcConnection
Dim ConnString As String ="Driver={Sybase System 11};SRVR=mySybaseServerName;DB=myDatabaseName;UID=myUsername;PWD=myPassword"
ODBCConnection = New OdbcConnection(ConnString)
ODBCConnection.Open()
...
ODBCConnection.Close()

For all other ODBC Drivers
USING C#.NET


using System.Data.Odbc ;
...
OdbcConnection ODBCConnection;
string ConnString ="Dsn=myDsn;Uid=myUsername;Pwd=myPassword";
ODBCConnection = New Odbc.OdbcConnection(ConnString) ;
ODBCConnection.Open() ;
...
ODBCConnection.Close() ;

USING VB.NET

Imports System.Data.Odbc
...
Dim ODBCConnection As OdbcConnection
Dim ConnString As String ="Dsn=myDsn;Uid=myUsername;Pwd=myPassword"
ODBCConnection = New Odbc.OdbcConnection(ConnString)
ODBCConnection.Open()
...
ODBCConnection.Close()

OLE DB .NET Data Provider (NameSpace : System.Data.OleDb)


The Microsoft .NET Framework Data Provider for OLE DB allow you to use native OLE DB providers (e.g. Microsoft.JET.OLEDB.4.0) to access database.

For JET OLE DB Provider


USING C#.NET


using System.Data.OleDb ;
...
OleDbConnection OleDbConnection;
string ConnString ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myPath\myJet.mdb;User ID=UserID;Password=Password" ;
OleDbConnection = New OleDb.OleDbConnection(ConnString);
OleDbConnection.Open() ;
...
OleDbConnection.Close();

USING VB.NET

Imports System.Data.OleDb
...
Dim OleDbConnection As OleDbConnection
Dim ConnString As String ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myPath\myJet.mdb;User ID=UserID;Password=Password"
OleDbConnection = New OleDb.OleDbConnection(ConnString)
OleDbConnection.Open()
...
OleDbConnection.Close()

For IBM AS/400 OLE DB Provider


USING VB.NET


Imports System.Data.OleDb
...
Dim OleDbConnection As OleDbConnection
Dim ConnString As String = "Provider=IBMDA400.DataSource.1;Data source=myAS400DbName;User Id=myUsername;Password=myPassword"
OleDbConnection = New OleDb.OleDbConnection(ConnString)
OleDbConnection.Open()
...
OleDbConnection.Close()

For Oracle OLE DB Provider


USING VB.NET


Imports System.Data.OleDb
...
Dim OleDbConnection As OleDbConnection
Dim ConnString As String =Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User ID=myUsername;Password=myPassword"
OleDbConnection = New OleDb.OleDbConnection(ConnString)
OleDbConnection.Open()
...
OleDbConnection.Close()

For SQL Server OLE DB Provider


USING VB.NET


Imports System.Data.OleDb
...
Dim OleDbConnection As OleDbConnection
Dim ConnString As String ="Provider=sqloledb;Data Source=myServerName;Initial Catalog=myDatabaseName;User Id=myUsername;Password=myPassword"
OleDbConnection = New OleDb.OleDbConnection(ConnString)
OleDbConnection.Open()
...
OleDbConnection.Close()


Thank You.

Regards,
Manoranjan Sahoo
Visit My Blog: http://msahoo.wordpress.com


Comments

Author: Mrs. Meetu Choudhary Nanda05 Jun 2009 Member Level: Gold   Points : 1

Good One!!!

All Combinations under one roof...

I liked th concept...

keep it up...

Author: Manoranjan Sahoo06 Jun 2009 Member Level: Gold   Points : 1

if anyone want more connection string then reply here i will update that one.

Guest Author: ahmad reza gharehkha11 Jun 2012

Very Very GOOD
thank you

Guest Author: ahmad reza gharehkha11 Jun 2012

Very Very GOOOOOOOD
thank you



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: