Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Backing up an Access 97 database which has a password

Posted on 2016-08-31
2
Medium Priority
?
21 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
1 Comment
 
LVL 25

Accepted Solution

by:
SStory earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

876 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