Connect Visual Basic.Net with MS Access Database (.accdb) with Password is secure way to manage Database. This tutorial is going to explain how to connect Visual Basic.Net with MS Access Database using code. Visual Basic .net requires a MS Access driver for connection. The driver is downloaded according to the installed version of MS Office. MS Office version is based on 32 or 64bit. Therefore, if you have already installed MS Office, you should know the office is 32 or 64bit.
Visual Basic.Net with MS Access Database (.accdb) with Password
From following link, you can download and install Microsoft Access Database Engine 2010 Redistributable
Now start MS Visual Basic .net, create a new project and save it. Open MS Access and create a new database with password protected. In the video it is explained how to set password on MS Access database.
It is good practice, if you use a different Module for database connection, you can change the Module name and form name. Here I am using Module and form1, for better understanding.
Copy and paste the code into Module1
Imports System.Data.OleDb Module Module1 Public DBConnection As New OleDbConnection Sub connectDatabase() Try If DBConnection.State = ConnectionState.Closed Then DBConnection.ConnectionString = "Provider=microsoft.ace.oledb.12.0; data source=" & Application.StartupPath & "\Database.accdb; Jet OLEDB:Database Password=12345 ;" DBConnection.Open() Form1.Text = " Connected" Else Form1.Text = " Connection is already Opend" End If Catch ex As Exception Form1.Text = ex.Message.ToString End Try End Sub End Module
Next step is to connect database with form1, so we will use the Sub connectDatabase() at form1 load.
Copy and paste the code at form start up
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Module1.connectDatabase() End Sub
Now run the program, you will see at form1.text “Connected” its mean now database with password is connected. If you set the password wrong, it will show “Not a valid password” at form1.text
Tagged with: Access 2013 connection string how to connect access database in vb How to connect password protected access database file how to connect password protected access database in vb net how to Connect to Ms Access database ms access database provider vb net access database example vb net connection string access accdb