CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Location
    Timisoara, Romania
    Posts
    460

    Question Error when trying to connect to pass protected db

    Hi all,
    I'm tring to connect to a password protected microsoft access mdb file and I get an error about the data base being opend exclusevly by another user. The thing is that the db is on my disk and is not opened.
    The connection string is like this:
    Code:
    OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + 
    				"User Id=admin;Password=xxx;Jet OLEDB:Engine Type=5;Persist Security Info=True;" +
    				"Data Source=C:\\Documents and Settings\\Mihai\\Desktop\\Imobiliare\\Vita\\BD\\anunturi.mdb");
    The thing is that if I try to open a mdb file that has no password and I remove the part about User Id and Password from the conn string it works.
    Can someone help me out?
    Thank you!
    Last edited by vma; September 4th, 2006 at 02:32 AM.
    You liked it? Please show your gratitude and rate it!

    There is no 'patch' for stupidity.

  2. #2
    Join Date
    Mar 2006
    Location
    Craiova, Romania
    Posts
    439

    Re: Error when trying to connect to pass protected db

    OLE DB, OleDbConnection (.NET)

    1.Standard security:

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin;Password=;"

    2.With password:

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB: Database Password=MyDbPassword;"

    3.Workgroup (system database):

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:System Database=system.mdw;"
    Try something like this if you have a password set for the database , not user password:
    Code:
    
     
    OleDbConnection aConnection = newOleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" +
     
    "Data Source=C:\\Documents and Settings\\Mihai\\Desktop\\Imobiliare\\Vita\\BD\\anunturi.mdb;" +
     
    "Jet OLEDB:Database Password=123;");
     
    aConnection.Open();
     
    aConnection.Close();
     
    
    Please post your exception.
    Last edited by creatorul; September 4th, 2006 at 06:20 AM.

  3. #3
    Join Date
    Oct 2003
    Location
    Timisoara, Romania
    Posts
    460

    Re: Error when trying to connect to pass protected db

    I tried that but is not working. I'm getting the same error. I now renounced OleDB and I'm using ODBC. Seems like it's working this way.
    Thank you!
    You liked it? Please show your gratitude and rate it!

    There is no 'patch' for stupidity.

  4. #4
    Join Date
    Mar 2006
    Location
    Craiova, Romania
    Posts
    439

    Re: Error when trying to connect to pass protected db

    You probably got this error :
    A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

    An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

    Additional information: Cannot start your application. The workgroup information file is missing or opened exclusively by another user.

    I think you need to have an ordinary file .mdw that stores the users .
    Note that the code with DataBase password works only if you have a database password ( which is different from a normal user/password).
    You can create a mdw file with Ms Access wizard ( Tool - Security - User Level Security Wizard) . This will generate a Security.mdw where the users you insert (with password) are kept.
    Then you can use it like this :
    Code:
    aConnection = newOleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\music.mdb;Jet OLEDB:System database=C:\\Security.mdw;User Id=gigi;Password=123;");
    
    
    I tried this code an works fine.

  5. #5
    Join Date
    Oct 2003
    Location
    Timisoara, Romania
    Posts
    460

    Re: Error when trying to connect to pass protected db

    I heard something about this mdw database so I lookd on my system drive and found a System.mdw. Tried with that one and still didn't work. I didn't know that you can create a mdw file. Anyway is not a good ideea with this mdw beacause I'm distributing this application and I don't want to have another file to take care about. For now ODBC is working so I'm leaving it this way!
    Thanks!
    You liked it? Please show your gratitude and rate it!

    There is no 'patch' for stupidity.

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