Templates by BIGtheme NET
Home / Visual Basic.Net / Visual Basic.Net with MS Access Database (.accdb) with Password
Microsoft VB.NET How to Connect Visual Basic.Net to MS Access Database (.accdb) with Password
Microsoft VB.NET How to Connect Visual Basic.Net to MS Access Database (.accdb) with Password

Visual Basic.Net with MS Access Database (.accdb) with Password

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

https://www.microsoft.com/en-us/download/details.aspx?id=13255

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

About Windows Tips

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*