🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.delphi.databases
Article #101

Re: Problems with an OLE Server opening Access DB

#101
From: Grant Black
Date: Mon, 04 May 1998 00:00
90 lines
3122 bytes

lxs@dei.unipd.it wrote in message <6ifaan$12c$1@nnrp1.dejanews.com>...
>I have a problem opening an Access DB in an OLE server created with
>Delphi 3.
>I have prepared a very short example that demonstrate how the server
>work (and crash):

<snip>

I access a Access DB from an Automation Server, but the BDE Native Access
drivers can be slow...
Here is my source code:

Automation server code:
,,,
procedure TMyAutoServer.Initialize;
begin
  // create a database to connect to the DB
  try
    db := TDatabase.Create(nil);
    with db do
    begin
      AliasName := 'ComsCtr';          // BDE alias to DB
      DatabaseName := 'aComsCtr'; // dummy not used
      LoginPrompt := False;
      Params.Add('USER NAME=MyUserName');
      Params.Add('PASSWORD=foo');
      Connected := TRUE;
    end;
  except
    // problem! BDE installed? Alias 'ComCentre' pointing to a ComCtr.MDB?
  end;
end;

// returns true if user logged in OK, False otherwise
function TMyAutoServer.Login: WordBool;
var
  qUsers     : TQuery;
begin
  result := BOOLFALSE; // by default
  qUsers := nil;       // suppress warning re qUsers may not have been
init'd
 try
    qUsers := TQuery.Create(nil);
    qUsers.DatabaseName := db.DatabaseName;
    qUsers.SQL.Add('SELECT *');
    qUsers.SQL.Add('FROM Users');
    qUsers.SQL.Add(WHERE   usr_Name = "'+FUserName+'"');
    qUsers.SQL.Add('AND   usr_Password = "'+FPassword+'"');
    qUsers.Open;
    if not qUsers.EOF then   // user found
    begin
      result := BOOLTRUE;
      FUserName        := qUsers.FieldByName('usr_Name').AsString;
      FUserAccessLevel := qUsers.FieldByName('usr_AccessLevel').AsInteger;
    end; // if located user
  finally
   if qUsers <> nil then qUsers.Free;
 end; // with dmodule
end;


and the client:
...
begin
  try
    ComControl := CreateOleObject('TVDComCtr.MyAutoServer);
  except
     on e: Exception do
        ShowMessage(e.Message);
  end;

  ComControl.UserName := eName.Text;
  ComControl.Password := ePassword.Text;
  if ComControl.Login then
    begin
      ModalResult := mrOK;
    end
  else
    begin
      MessageBeep(MB_ICONASTERISK);
      FlashWindow(LoginDlg.Handle,FALSE);
    end;
end;



Regards,
Grant
Technical Details
Message-ID: <6iip2b$sl$1@news.iconz.co.nz>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6ifaan$12c$1@nnrp1.dejanews.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: ff75c,16c365d08f9762f1
X-Google-Attributes: gidff75c,public
X-Google-Thread: ffff5,16c365d08f9762f1
X-Google-Attributes: gidffff5,public
X-Google-Thread: 10baee,16c365d08f9762f1
X-Google-Attributes: gid10baee,public
X-Google-Thread: fd196,16c365d08f9762f1
X-Google-Attributes: gidfd196,public
From: "Grant Black" <grant@tvd.co.nz>
Subject: Re: Problems with an OLE Server opening Access DB
Date: 1998/05/04
Message-ID: <6iip2b$sl$1@news.iconz.co.nz>
X-Deja-AN: 349920186
References: <6ifaan$12c$1@nnrp1.dejanews.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3007.0
Organization: Internet Company of New Zealand
Newsgroups: comp.lang.pascal.delphi.databases,comp.lang.pascal.delphi.misc,borland.public.delphi.oleautomation,borland.public.delphi.database.desktop