Solved

Backing up an Access 97 database which has a password

Posted on 2016-08-31
2
10 Views
Last Modified: 2016-10-22
Hi,

I've been given a vb.net program to take over from another developer, which uses an Access 97 database. The user has asked me to put a password on the database to stop it being opened up at free will.
The program runs a daily backup of the database using the  DAO Database engine. I'm not familiar with this, but at the moment, it cannot backup the database, as it keeps saying there's an invalid password.

Where do I put the password in this code, and how do I do it? (The error is on the dbo.CompactDatabase method)

 Private Sub asyncBackupDaily(ByVal state As Object)

        Try
            sql = "SELECT * FROM [System Settings]"
            dataAd = New OleDb.OleDbDataAdapter(sql, con)
            dataSet = New DataSet
            dataAd.Fill(dataSet)

            Dim currentDB As String = readIni("DATABASE", directorypath & "settings.ini")
            Dim newDB As String = dataSet.Tables(0).Rows(0).Item("backupPath") & "backup" & DateTime.Now.ToString("yyyy-dd-MM") & ".mdb"

            My.Computer.FileSystem.CopyFile(currentDB, dataSet.Tables(0).Rows(0).Item("backupPath") & "backup" & DateTime.Now.ToString("yyyy-dd-MM") & "-nc.mdb", True)

            If My.Computer.FileSystem.FileExists(newDB) = True Then
                My.Computer.FileSystem.DeleteFile(newDB)
            End If

            Dim dbo As New DAO.DBEngine
            dbo.CompactDatabase(dataSet.Tables(0).Rows(0).Item("backupPath") & "backup" & DateTime.Now.ToString("yyyy-dd-MM") & "-nc.mdb", newDB)

            Try
                My.Computer.FileSystem.DeleteFile(dataSet.Tables(0).Rows(0).Item("backupPath") & "backup" & DateTime.Now.ToString("yyyy-dd-MM") & "-nc.mdb")

            Catch ex As Exception
            End Try

            MsgBox("Daily auto-backup successful!", MsgBoxStyle.OkOnly, "Success")

        Catch ex As Exception
            errorLog(ex)

        End Try
    End Sub
0
Comment
Question by:David Hooley
2 Comments
 
LVL 25

Accepted Solution

by:
SStory earned 500 total points
ID: 41778163
There is a Microsoft KB article on one way to open it if i just a DB password, and not user level security. The sample code is:
 Dim db As DAO.Database
 Dim ws As DAO.WorkSpace
 Dim rst As DAO.Recordset
 Set ws = DBEngine.WorkSpaces(0)
 Set db = ws.OpenDatabase _
 ("C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb", _
 False, False, "MS Access;PWD=northwind")
 Set rst = db.OpenRecordset("Customers", dbOpenDynaset)
 If rst.RecordCount > 0 Then
   rst.MoveLast
   MsgBox rst!CustomerID
 End If

Open in new window

source: https://support.microsoft.com/en-us/kb/209953

Also with Oledb it will be in the connection string, which you don't show. (the con varible)
Here is how to do the connection strings (2007-2013:  
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;
Jet OLEDB:Database Password=MyDbPassword;

Open in new window

source: http://www.connectionstrings.com/access/
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now