Results 1 to 14 of 14
  1. #1
    Join Date
    May 2004
    Posts
    90

    Unanswered: Connecting to password protected DB

    How do I connect to a username and password protected database using visual basic? Thanks

  2. #2
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    Here is an example:

    Dim cn as ADODB.Connection
    Dim rs as ADODB.Recordset

    Set cn = new ADODB.Connection
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Password=TestPass;Data Source=C:\Test.mdb;Persist Security Info=False;Exclusive=0"
    cn.open

    set rs = new ADODB.recordset
    rs.ActiveConnection = cn
    rs.Open "SELECT * FROM Table1"

    rs.Close
    cn.Close
    Set rs=Nothing
    Set cn = Nothing
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  3. #3
    Join Date
    May 2004
    Posts
    90
    Okay, let me check if it works
    Last edited by lskuff; 06-01-04 at 13:38.

  4. #4
    Join Date
    Jul 2003
    Location
    Australia
    Posts
    217

    ???

    That apply to database-level security password, isn't it ??

    But how about user-level security password ??
    Last edited by Lepanto; 06-01-04 at 05:26. Reason: needed more info

  5. #5
    Join Date
    May 2004
    Posts
    90
    Yes, I am sorry I posted that it worked so soon. I was just wanting it to work so bad. But I have a USER LEVEL security scheme and I tried what was posted above and it said something that it could not find the workgroup so I added something to the connect string so it looks like this:

    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Test;Password=test;Data Source=C:\Test\TestDB.mdb;Persist Security Info=False;Exclusive=0;Jet OLEDBystem database=C:\Test\Secured.mdw"

    and that seemed to fix the workgroup error but now I am getting the error: Could not find installable ISAM.

    I have download the latest version of of the Microsoft Data Access Components [MDAC] - (ver 2.8) but that did not fix the problem. I went to microsoft site and found this: http://support.microsoft.com/?kbid=209805
    it seems like it is what I need to fix the problem, but no. I tried everything it said to no avail.
    Anyone have any ideas?

  6. #6
    Join Date
    May 2004
    Posts
    90
    Oh, and I have access 2000 if that matters at all.

  7. #7
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    Take a look at this link which

    http://www.able-consulting.com/ADO_Conn.htm

    which has a very large collection of ADO and ADO.NET connection strings.

    Does that help?
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  8. #8
    Join Date
    May 2004
    Posts
    90
    Okay, I am making progress.
    I have set up the connection as follows:
    --------------------------------------------
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    FixUpRefs
    Set cn = New ADODB.Connection

    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=c:\MyPath\TestDB.mdb;" & _
    "Jet OLEDBystem Database=Secured.mdw", _
    "myusername", "mypassword"

    Set rs = New ADODB.Recordset
    rs.ActiveConnection = cn
    .
    .
    .
    ------------------------------------
    Now I get the error: You do not have the necessary permissions to use the 'c:\MyPath\TestDC.mdb' object. Have your system admin or the person who created this object establish the apropriate permissions for you.

    I don't know how to do that. I have run the security wizard and have set up all the permissions like they are supposed to be. I get this error even when logging in using my Administrator account and it does not matter whether I put an admin password or a user password in the connection string I still get the same error.

    I am sorry that this is taking so long to work out it just seems like every time that I get past one problem another problem pops up. It does not seem like this should be so difficult.

  9. #9
    Join Date
    May 2004
    Posts
    90
    If someone could just tell me a yes or no on whether my code is correct that would help a lot. Because if it is correct I know the problem is someplace else. Thanks

  10. #10
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    Your code looks good however try these two suggestions:

    Set cn = New ADODB.Connection

    cn.Provider = "Microsoft.Jet.OLEDB.4.0"
    cn.Properties("Data Source").Value = "c:\MyPath\TestDB.mdb"
    cn.Properties("User ID").Value = sUserName
    cn.Properties("Password").Value = sPassword
    cn.open

    or

    Set cn = New ADODB.Connection

    cn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
    "dbq=c:\MyPath\TestDB.mdb" & _
    "SystemDB=c:\somepath\mydb.mdw;", _
    "myUsername", "myPassword"

    Does that work?
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  11. #11
    Join Date
    May 2004
    Posts
    90

    Angry

    Well with this code:

    Set cn = New ADODB.Connection
    cn.Provider = "Microsoft.Jet.OLEDB.4.0"
    cn.Properties("Data Source").Value = "c:\MyPath\TestDB.mdb"
    cn.Properties("User ID").Value = sUserName
    cn.Properties("Password").Value = sPassword
    cn.Properties("Jet OLEDBystem database").Value = "Secured.mdw
    cn.open

    I still get the permission error that I was getting before (it is explained above).

    With this code:

    Set cn = New ADODB.Connection

    cn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
    "dbq=c:\MyPath\TestDB.mdb" & _
    "SystemDB=c:\somepath\mydb.mdw;", _
    "myUsername", "myPassword"

    It said: [Microsoft][ODBDC Microsoft Access Driver] Not a valid file name"


  12. #12
    Join Date
    May 2004
    Posts
    90

    Angry

    Well, I guess if that if I do not get this problem worked out by today then I will have to call Microsoft Tech Support. I just wish I would have done it a while ago so I did not waste so much time on this.

  13. #13
    Join Date
    May 2004
    Posts
    90
    Hello,
    I just want to thank everyone who helped me solve this problem. I finally figured it out today. There was a mistake in the module and there was a variable that was declared twice. After fixing that it worked perfectly. It is good because I have a meeting tomorrow to present the database. Thanks again.

  14. #14
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    Always using the command

    Option Explicit

    at the head of ALL your code modules, this prevents errors like this one from occuring.

    All the best.
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

Posting Permissions

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