i've been asked a few times how to open an access database that has a password protection so i've put a quick sample together , here's the code ( using OleDb ) and an attached example source :
VB Code:
Imports System.Data.OleDb '//// ^^^ at the very top of your form's code window. '//////// Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strPath As String = Application.StartupPath & "\access_net.mdb" Dim strPass As String = "sysop" '/// password for the access file ( in this instance being "sysop" ) Dim Connection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";Jet OLEDB:Database Password=" & strPass & ";User ID=Admin;Persist Security Info=True" Dim Command As String = "SELECT * FROM Table1" OpenAccessFile(Connection, Command) '/// lets open the password protected access file. End Sub Private Sub OpenAccessFile(ByVal strConnection As String, ByVal strCommand As String) Try Dim objDbConnection As New OleDbConnection(strConnection) objDbConnection.Open() '///open a new connection. Dim objCommand As New OleDbCommand(strCommand, objDbConnection) Dim objAdaptor As OleDbDataAdapter objAdaptor = New OleDbDataAdapter(objCommand) Dim objDataSet As New DataSet() objAdaptor.Fill(objDataSet, "Table1") DataGrid1.DataSource = objDataSet.Tables("Table1") '///fill a datagrid with the recordset objDbConnection.Close() objCommand.Dispose() objAdaptor.Dispose() objDataSet.Dispose() Catch ex As Exception MsgBox(ex.Message) End Try End Sub





Reply With Quote