Solved

Backing up an Access 97 database which has a password

Posted on 2016-08-31
2
9 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

758 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