C# ODBC Connection

An instance of the OdbcConnection Class in C# is supported the ODBC Data Provider. The OdbcConnection instance takes Connection String as argument and pass the value to the Constructor statement. When the connection is established between C# application and the Data Source the SQL Commands will execute with the help of the Connection Object and retrieve or manipulate data in the database.

connetionString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=yourdatabasename.mdb;"; cnn = new OdbcConnection(connetionString);

Once the Database activities is over you should be closed the Connection and release the Data Source resources . The Close() method in OdbcConnection Class is used to close the Database Connection.

cnn.Close();

The Close method rolls back any pending transactions and releases the Connection from the Database connected by the ODBC Data Provider .

Full Source C#
using System; using System.Windows.Forms; using System.Data.Odbc; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string connetionString = null; OdbcConnection cnn ; connetionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=yourdatabasename.mdb;"; cnn = new OdbcConnection(connetionString); try { cnn.Open(); MessageBox.Show ("Connection Open ! "); cnn.Close(); } catch (Exception ex) { MessageBox.Show("Can not open connection ! "); } } } }