0

When I run my program and press one of my login buttons it says missing connection or connection string The connection string is already there

procedure TFmLogin.BtnLogin2Click(Sender: TObject);
begin
  ADOUser.ConnectionString:=Connstr;
  ADOUser.TableName:='TblUser';
  ADOUser.Open;
  if ADOUser.Locate('Username', EdUsename.Text,[]) then    
  begin
    if EdPassword.Text=ADOUser['Pword'] then
    begin
      if ADOUser['AdminLevel']>=0 then
  begin
    FmBrowse.Delete;
    Close
  end
  else
  showmessage('password invalid.');
    End;
  end
  else
  Begin
showmessage('Username invalid.');
  end;
  Close;
end;

I can't find anywhere in this procedure that it should be looking for a connection string and wondered if anyone could help me figure out where I've gone wrong

RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • 1
    What's in `ConnStr`? You don't show it being declared or any value being assigned to it. That's the obvious first place to look, I'd think. – Ken White Apr 11 '13 at 12:24
  • It's assigned globally, – Matthew Walker Apr 11 '13 at 12:36
  • Const ConnStr='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=cardb.mdb;Persist Security Info=False'; – Matthew Walker Apr 11 '13 at 12:37
  • It's worrking with the other 3 delete functions and this is copied code from the others – Matthew Walker Apr 11 '13 at 12:37
  • 1
    Set a breakpoint on the `ADOUser.ConnectionString` line and step through the code with the debugger. There's no information here that we can use to figure this out for you; you'll have to just step through and look to see what's happening. You may have a different `ConnStr` in scope or something, but we're not going to be able to see that from here. – Ken White Apr 11 '13 at 12:47

2 Answers2

0

Usually in ADO u have to write the full path of your database.

and yours is

Const ConnStr='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=cardb.mdb;Persist Security Info=False';

try to change the Source=cardb.mdb; to Source=[[full path]]\cardb.mdb;

Hope this works.

Dreamer64
  • 923
  • 2
  • 13
  • 30
0

Path doesnt matter as long as the DB is in the same place as where is executable is being compiled. If not then yes you need to put in the full path as Dreamer64 suggested + His connecting before auth, I think he is missing the username his connections string and the passwords not being saved on the component. Try :

 Const ConnStr='Provider=Microsoft.Jet.OLEDB.4.0;'+
'Persist Security Info=False;'+
'User ID=[yourdbusername];'+
'Initial Catalog=[yourtablename];'+
'Data Source=cardb.mdb;';

Now on your ado component right click it and edit string, next to that build string, the first tab should present you with the path username and password fill in the password and test connection, if test succeeds, you are good to go.

Senjuti Mahapatra
  • 2,570
  • 4
  • 27
  • 38
Gavin
  • 1