CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 1999
    Posts
    78

    How to Open a Password Protected MDB thru Data control

    Hi
    I've set a paasword for a MDB (MS Access created Database), but I don't know how to set the password as well for the Data Control bound to the Database, in DESIGN TIME. Which property of Data Control is actually used to set the password (During Design-Time) in order to gain access to a password-protected MDB during run-time ? I don't want to use DAO to open the database and then assign it to the data control, coz it's quite troublesome and tedious to do so. Thanks in advance, sincerely


  2. #2

    Re: How to Open a Password Protected MDB thru Data control

    Assuming you're using DAO data control, I believe you'd set the connect property to something like the following, after specifying the path of the database.

    "pwd=thepassword"

    Or you can specify the path in the connect property as well:

    "C:\Mydatabase;pwd=thepassword"

    At least this is how I think it should work; never done it this way myself.


  3. #3
    Guest

    Re: How to Open a Password Protected MDB thru Data control

    First of all check what you have in DatabaseName property of DC. If you used Open Dialog to choose the database, probably you have the path only without DB name. For example if your database is "C:\MyData\MyDB\MyTestDB.mdb" VB will set it to "C:\MyData\MyDB", so you have to add "\MyTestDB.mdb" manually. This is the most common reason of problem. After that you need to type in Connect Property ;pwd=mypassword. Now RecordSource property is available without any error messages. This works only with Access 97 DB format. If you have to use for some reason an intrinsic DC with Access 2000 DB, you need to insert DAO recordset object between DC and DB like this:

    Dim db as Database
    Dim Wrkspc as WorkSpaces
    Dim strPass as string
    Dim DBName as string
    Dim rsMyRecordset as Recordset
    Dim strSQL as string

    strPass = ";pwd=PASSWORD"
    strSQL = "SELECT * FROM MyTable"
    DBName="C:\.....\MyDB.mdb"
    set Wkspc=Workspaces(0)
    set db=Wkspc.OpenDatabase(DBName, false, false, strPass)
    set rsRecordset = db.OpenRecordset(strSQL, dbOpenDynaset)
    set Data1.Recordset=rsRecordset




    HTH
    Vlad


  4. #4
    Join Date
    Jun 1999
    Posts
    78

    Thank You All, Problem Solved

    Hi
    Thank You All very much, the problem had been solved, b4 that I got an error meesgae like couldn't find ISAM driver, but now it has been solved, coz the Connect property of datacontrol doesn't recognize "Access;pwd=password" or "DatabasePathName;pwd=password", just type in ";pwd=Password" will do, no wonder I got errors... Thanks anyway.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured