My code is:

System.Data.OleDb
Public Class Form1
    Dim cn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DBB.mdb;")
            cn.Open()
            cmd = New OleDbCommand("select * from TbA", cn)
            dr = cmd.ExecuteReader
            While dr.Read()
                TextBox1.Text = dr(0)
                TextBox2.Text = dr(1)
                TextBox3.Text = dr(2)                
            End While
        Catch
        End Try
        dr.Close()
        cn.Close()
    End Sub
End Class

It works for a database without password. But for a database with password and the string:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DBB.mdb;Jet OLDB:Database Password=xxx"

I get an error: "Object reference not set to an instance of an object."
Where wrong?

Thanks!

I don't think this approach can handle strange charaters in the password like ( or ). Check that your password only contains alphanumeric characters.

I don't think this approach can handle strange charaters in the password like ( or ). Check that your password only contains alphanumeric characters.

Thanks Chris!

The password contains only letters. I changed it to "123", but I get the same error.

In fact, the error handling lines, (Try / Catch / End try), cause an incorrect error indication.
If I removed these lines, I get the following error:
"Could not find installable ISAM"

NB: The error occurs only if the database is password protected!
For unprotected database, code works without error.

This article has been dead for over six months. Start a new discussion instead.