Solved

Password protecting an mdb

Posted on 2001-06-24
9
182 Views
Last Modified: 2010-05-02
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
Comment
Question by:groone
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 6223090
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
 
LVL 3

Author Comment

by:groone
ID: 6223110
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
 
LVL 33

Expert Comment

by:hongjun
ID: 6223133
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
 
LVL 1

Accepted Solution

by:
ahmadpj earned 100 total points
ID: 6223181
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6223303
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
 
LVL 33

Expert Comment

by:hongjun
ID: 6223339
groone,
do you managed to set the database password?

hongjun
0
 
LVL 3

Author Comment

by:groone
ID: 6224196
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
 
LVL 1

Expert Comment

by:ahmadpj
ID: 6226285
I'm glad to be useful here:)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6226312
Thanks for thanks to me, too
;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 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

26 Experts available now in Live!

Get 1:1 Help Now