Solved

Access / Delphi Password Problems.....

Posted on 2004-09-13
7
284 Views
Last Modified: 2010-04-05
Hi experts,

When ever I try and set a password on the access DB my app is connecting to I get the following error:

---------------------------
Microsoft Data Link Error
---------------------------
Test connection failed because of an error in initializing provider. Cannot start your application. The workgroup information file is missing or opened exclusively by another user.
---------------------------
OK  
---------------------------

If any of you experts could please help me with this I would really appriciate your help and advise.  What I want to do is then hard code the DB password and then have a table in the DB that contains user set username and password to actually log into the app.

I am connecting to the DB the following way:

********************************************************************

function GetDBLOCATION : String;
var
  Reg : TRegistry;
begin
  Result := '';
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey ('\Software\'+application.title, true) then
      Result := Reg.ReadString ('DBNAME');
      Reg.CloseKey;
  finally
    Reg.Free;
  end;
end;

procedure TForm1.Startup(Sender: TObject);
var
  Reg : TRegistry;
  flag : Boolean;
begin
  flag := True;
  if Not DBConnected then
  begin
    DBPath := GetDBlocation;
    while not FileExists(DBPath) do
    begin
      OpenDialog1.Title := 'Database Location';
      OpenDialog1.Filter := 'Access Database|*.mdb';
      if OpenDialog1.Execute then
      begin
        Reg := TRegistry.Create;
        DBPath := OpenDialog1.FileName;
        try
          Reg.RootKey := HKEY_CURRENT_USER;
          Reg.OpenKey ('\Software\'+application.title, true); // Write path and address to register
          Reg.CloseKey;
        finally
          Reg.Free;
        end; // try
      end // if
      else
      begin
        showmessage('Unable to connect to the Database.');
        flag:=false;
        break;
      end;
    end;
    if flag then
      BankManagerConnection.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='
                                + DBPath
                                + ';Persist Security Info=False';
    DBConnected := True;
  end;
end;

********************************************************************

What I want to do is:
1. App starts and creates a connection to the DB.
2. Form displayed user then inputs their details, if in table then login successful.

I need help with step 1.

Please help, desperate  :o(  Any questions please ask.

More points on offer for working solution.

Bego.
0
Comment
Question by:begonz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 12042298
Try setting your connectionstring to the following:

BankManagerConnection.ConnectionString
  := 'Provider=Microsoft.Jet.OLEDB.4.0;Password="YourPsw";Data Source='
      + DBPath
      + 'Mode=ReadWrite|Share Deny None;'
      + 'Persist Security Info=False';

0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 500 total points
ID: 12042597
Hello
if the Access file has  a password, add this to the connectionstring

'Jet OLEDB:Database Password=thepassword'

it's will look like
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='
                                + DBPath
                                + ';Persist Security Info=False;Jet OLEDB:Database Password=thepassword';

and if you the user to enter the password then show Inputbox for the password and then add it to the connecitonString

HTH

Regards,
Mohammed
0
 
LVL 6

Expert Comment

by:bpana
ID: 12042637
add the password to the connection string and set Persist Security Info = True. also set Login Prompt = False
and make sure the database is not opened (is not in use)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:meadorj
ID: 12044164
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey ('\Software\'+application.title, true); // Write path and address to register
Reg.CloseKey;

This is incorrect.  You have to write to the registry useing WriteString.  So it should be:

Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey ('\Software\'+application.title, true); // Write path and address to register
Reg.WriteString(OpenDialog1.FileName)
Reg.CloseKey;
0
 

Expert Comment

by:meadorj
ID: 12044177
Then somewhere you need to set DBPath equal to OpenDialog1.FileName.
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 12046612
Hi

Just a comment.

I have seen this problem before with ADO but can't remember the reason (I use DAO with Access - it is lots faster and all the databound VB controls work with it - they dont with the ADO).

I suggest that you re-install the MDAC (2.7) followed by the Jet Engine (Jet40Sp3_Comp.exe).

I have just checked and the MDAC is now 2.8 - http://www.microsoft.com/downloads/details.aspx?FamilyID=6c050fe3-c795-4b7d-b037-185d0506396c&displaylang=en

The Jet Engine is not included with the MDAC anymore, and looks like Microsoft are being a bit coy about giving it you now - you can dowload it from http://www.omegatron.nl/default.asp?target=download.asp

Voodooman

0
 

Author Comment

by:begonz
ID: 12060429
Thanks Mohammed exactly what I wanted.  Finally got it connected last night with only minor change to my existing code.

I have also managed to get my user login form working as well.

Thanks again.

Bego.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 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