Results 1 to 9 of 9

Thread: Opening a database with password on VB (DAO)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    110

    Opening a database with password on VB (DAO)

    ok i gave a password for my access database, now when i open it in VB, it says invalid password, what could be my code to open the password?

    VB Code:
    1. set db = DBEngine.OpenDatabase(App.Path & "\database.mdb")
    2. set rs = db.openrecordset("table")

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Opening a database with password on VB (DAO)

    You need to provide more parameters to the OpenDatabase function (specifically the Connect parameter), eg:
    VB Code:
    1. set db = DBEngine.OpenDatabase(App.Path & "\database.mdb", , ,"ODBC; pwd=mypassword")
    (I'm afraid I have no idea if the connect string here is correct!)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    110

    Re: Opening a database with password on VB (DAO)

    yeah i couldnt make it work

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Opening a database with password on VB (DAO)

    I'm sure there are several working examples on the forums, a search should find them.

    Oh and by the way, in case it helps the default username for Access databases with passwords is Admin

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    110

    Re: Opening a database with password on VB (DAO)

    what would be the next best thing for protecting your access database without disrupting your vb codes? hide it?

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Opening a database with password on VB (DAO)

    Hiding it would do nothing at all in many cases, as many people have 'view hidden files' turned on.

    If you have even the slightest need for keeping the data secure, get the password working. "disrupting" your code should not be an issue for you.

    There are working examples on the forums of how to make this particular code work.

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Opening a database with password on VB (DAO)

    Try this

    VB Code:
    1. DBEngine.DefaultUser = "username"
    2.     DBEngine.DefaultPassword = "MyPassword"
    3.    
    4.     DoEvents
    5.    
    6.     'Open the database
    7.     Set gdbRWTS = Workspaces(0).OpenDatabase(pathtodatabase)

  8. #8
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Opening a database with password on VB (DAO)

    There are numerous methods you could use with Access to secure the data.. A lot of this will depend on the version that you are using..

    You can prevent access to the database window and disable full menus and special keys.
    You could save the database as an mde (but make sure you have a back-end front-end split otherwise you will be unable to develop) and more importantly make sure you have a back-up to revert to.

    It does also depend on what you are wanting to hide and from who. If it is the code then switching to an MDE will prevent access. If it is the table data itself then you have far less option.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  9. #9
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Opening a database with password on VB (DAO)

    Quote Originally Posted by si_the_geek
    You need to provide more parameters to the OpenDatabase function (specifically the Connect parameter), eg:
    VB Code:
    1. set db = DBEngine.OpenDatabase(App.Path & "\database.mdb", , ,"[B]ODBC; [/B] pwd=mypassword")
    (I'm afraid I have no idea if the connect string here is correct!)
    The bold part doesn't seem to be needed.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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