Connection string for odbc in C sharp

First create a odbc driver as specified below.

goto control panel->system and security->Administrative tools->data sources(odbc)

step1)click on add

step2)select sql server

step3)specify ur sql server name and create the driver

IN C sharp write the following commands to get connect:

Odbcconnection con=new Odbcconnection(“Driver=<drivername>;Server=<servername>;UID=<username>;PWD=<passwd>;“);

if your sql server is authorized then no need of specifing user name and password

eg:    Odbcconnection con=new Odbcconnection(“Driver={SQL server};Server=shivaji-pc;“);

if not authorized then.

eg:    Odbcconnection con=new Odbcconnection(“Driver={SQL server};Server=shivaji-pc;UID=shivaji;PWD=1234;“);

sample program to execute a query:

public viod exequery( )


Odbcconnection con=new Odbcconnection(“Driver={SQL server};Server=shivaji-pc;“);

Odbccommand comd=new Odbccommand(“insert into student values(’21’,’shivaji’);“,con);

con.Open( );

comd.ExecuteNonQuery( );

con.Close( );



you can also create odbc drivers for oracle and other db server in similar manner.

you can also connect directly to db server without using odbc.

<<there are many other ways to get connect>>