ADO.NET OLEDB Connection

The OleDbConnection class enables connectivity to databases through the OLEDB Data Provider. When working with VB.Net applications, an instance of the OleDbConnection class is created to establish the connection. The constructor of the OleDbConnection class accepts a connection string as an argument, which is then used to establish the connection.


After creating an instance of the OleDbConnection class and successfully establishing the connection, SQL commands can be executed using the Connection Object. These SQL commands allow for data retrieval, manipulation, or any other necessary operations within the connected database.

Once the database activities are completed, it is essential to close the connection and release the associated resources. In the case of SqlConnection (which is not applicable for OleDbConnection), the Close() method is used to close the database connection. This method also rolls back any pending transactions and releases the connection from the database connected via the OLEDB Data Provider.

However, it's important to note that the Close() method mentioned above is specific to the SqlConnection class and does not apply to the OleDbConnection class. The OleDbConnection class provides its own Close() method to close the connection and release resources.

Full Source VB.NET
Imports System.Data.OleDb Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim connetionString As String Dim cnn As OleDbConnection connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=yourdatabasename.mdb;" cnn = New OleDbConnection(connetionString) Try cnn.Open() MsgBox("Connection Open ! ") cnn.Close() Catch ex As Exception MsgBox("Can not open connection ! ") End Try End Sub End Class

You have to provide the necessary informations to the Connection String.

connetionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = yourdatabasename.mdb;"

From the above statement replace yourdatabasename.mdb to the actual names.