Results 1 to 1 of 1

Thread: Opening an Access database thats password protected.

  1. #1

    Thread Starter
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Opening an Access database thats password protected.

    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:
    1. Imports System.Data.OleDb
    2. '//// ^^^ at the very top of your form's code window.
    3.  
    4. '////////
    5.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    6.         Dim strPath As String = Application.StartupPath & "\access_net.mdb"
    7.         Dim strPass As String = "sysop" '/// password for the access file ( in this instance being "sysop" )
    8.  
    9.         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"
    10.         Dim Command As String = "SELECT * FROM Table1"
    11.         OpenAccessFile(Connection, Command) '/// lets open the password protected access file.
    12.     End Sub
    13.  
    14.     Private Sub OpenAccessFile(ByVal strConnection As String, ByVal strCommand As String)
    15.         Try
    16.             Dim objDbConnection As New OleDbConnection(strConnection)
    17.  
    18.             objDbConnection.Open() '///open a new connection.
    19.  
    20.             Dim objCommand As New OleDbCommand(strCommand, objDbConnection)
    21.             Dim objAdaptor As OleDbDataAdapter
    22.             objAdaptor = New OleDbDataAdapter(objCommand)
    23.             Dim objDataSet As New DataSet()
    24.             objAdaptor.Fill(objDataSet, "Table1")
    25.             DataGrid1.DataSource = objDataSet.Tables("Table1") '///fill a datagrid with the recordset
    26.  
    27.             objDbConnection.Close()
    28.             objCommand.Dispose()
    29.             objAdaptor.Dispose()
    30.             objDataSet.Dispose()
    31.         Catch ex As Exception
    32.             MsgBox(ex.Message)
    33.         End Try
    34.     End Sub
    Attached Files Attached Files
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width