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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

Password protecting an mdb

Please someone show me how to protect a database and how to open the protected database.  Dont give me some long example, just get to the point.

    Set myDB = DBEngine(0).CreateDatabase(FileName, dbLangGeneral)
    Set myDB = DBEngine.Workspaces(0).OpenDatabase(FileName)

    blah blah add fields

    myDB.close

Thanks!
0
groone
Asked:
groone
  • 3
  • 2
  • 2
  • +1
1 Solution
 
hongjunCommented:
How to protect a database
==========================
1. File->Open. Then open the access file as "Exclusive".
2. Tools->Security->Set Database Password
3. Type and confirm your database password.
That's all.

How to open the protected database (I am using ADO)
===================================================
' You got to add Microsoft ActiveX Data Objects 2.1 or other version library
Dim objConn as ADODB.Connection
Dim FileName as string
Dim passwd as string

FileName = "C:\Windows\Desktop\db1.mdb"
passwd = "abcdef"

Set objConn = New ADODB.Connection
objConn.Open "Driver={Microsoft Access Driver (*.mdb)};dbq=" & FileName & ";uid=sa;pwd=" & passwd & ";"
...

hongjun
0
 
grooneAuthor Commented:
Notice the database is being created by code using dao3.5 not ADO.  I am creating the database on the fly and need it to be password protected as it is being created from within the VB 6.0 code.  Sorry, thought the question would have been obvious.
0
 
hongjunCommented:
Taken from MSDN. Might be of help to you.

Sub OpenDatabaseX()

   Dim wrkJet As Workspace
   Dim dbsNorthwind As Database
   Dim dbsPubs As Database
   Dim dbsPubs2 As Database
   Dim dbsLoop As Database
   Dim prpLoop As Property

   ' Create Microsoft Jet Workspace object.
   Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)

   ' Open Database object from saved Microsoft Jet database
   ' for exclusive use.
   MsgBox "Opening Northwind..."
   Set dbsNorthwind = wrkJet.OpenDatabase("Northwind.mdb", _
      True)

   ' Open read-only Database object based on information in
   ' the connect string.
   MsgBox "Opening pubs..."
   Set dbsPubs = wrkJet.OpenDatabase("Publishers", _
      dbDriverNoPrompt, True, _
      "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")

   ' Open read-only Database object by entering only the
   ' missing information in the ODBC Driver Manager dialog
   ' box.
   MsgBox "Opening second copy of pubs..."
   Set dbsPubs2 = wrkJet.OpenDatabase("Publishers", _
      dbDriverCompleteRequired, True, _
      "ODBC;DATABASE=pubs;DSN=Publishers;")

   ' Enumerate the Databases collection.
   For Each dbsLoop In wrkJet.Databases
      Debug.Print "Database properties for " & _
         dbsLoop.Name & ":"

      On Error Resume Next
      ' Enumerate the Properties collection of each Database
      ' object.
      For Each prpLoop In dbsLoop.Properties
         If prpLoop.Name = "Connection" Then
            ' Property actually returns a Connection object.
            Debug.Print "  Connection[.Name] = " & _
               dbsLoop.Connection.Name
         Else
            Debug.Print "  " & prpLoop.Name & " = " & _
               prpLoop
         End If
      Next prpLoop
      On Error GoTo 0

   Next dbsLoop

   dbsNorthwind.Close
   dbsPubs.Close
   dbsPubs2.Close
   wrkJet.Close

End Sub

hongjun
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ahmadpjCommented:
Hi, groone, This is the answer:

Dim MyDB As Database
Dim FileName As String

FileName = "C:\win98\desktop\db1.mdb" 'change it as your will

Set MyDB = DBEngine(0).CreateDatabase(FileName, dbLangGeneral)

'set a password to it..
MyDB.NewPassword "", "MyPass"
MyDB.Close

'opening protected database
Set MyDB = DBEngine.OpenDatabase(FileName, False, 0, ";pwd=MyPass")
MyDB.Close


 good Luck.
0
 
Richie_SimonettiCommented:
I think ahmadpj get the answer but i am not sure of this line:
Set MyDB = DBEngine.OpenDatabase(FileName, False, 0, ";pwd=MyPass")
maybe it should be:
Set MyDB = DBEngine.OpenDatabase(FileName, 0,false, ";pwd=MyPass")
0
 
hongjunCommented:
groone,
do you managed to set the database password?

hongjun
0
 
grooneAuthor Commented:
Thanks!  Worked perfectly except you had the false and 0 in the wrong place other than that was a good answer.  Brief and to the point.
0
 
ahmadpjCommented:
I'm glad to be useful here:)
0
 
Richie_SimonettiCommented:
Thanks for thanks to me, too
;)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now