Board index » delphi » Problem connecting to multiple databases ...

Problem connecting to multiple databases ...

I am having a problem connecting to various databases.  One pass thru
the application and it's fine.  But on the 2nd attempt, I get an Invalid
Thread ID error.
The problem is related to connecting and disconnecting databases.  I
just wondered how one would connect and disconnect to multiple
databases?  Am I doing it right below, or is there some other free and
release method I should be calling as well?

Here is the code:
 for i := 0 to DBIndex-1 do
 begin
  //This array is just an array of strings representing the full path of
a database
  DatabasePath := DBArray[i];
  tempstring := ExtractFileName(DatabasePath);
  AliasName := Copy(tempstring,1,Pos('.', tempstring)-1);
  dmJobTrack.db.Connected := False;
  dmJobTrack.db.AliasName := AliasName;
  dmJobTrack.db.DatabaseName := 'db';
  try
   dmJobTrack.db.Connected := True;
  except
   showmessage('Error');
  end;
  dmJobTrack.db.Connected := False;
 end;

Hopefully someone can help.

Thanks!
Melissa

 

Re:Problem connecting to multiple databases ...


I might be missing something, but where to you set the TDatabase.Params PATH
to use the database path extracted from DBArray?  Or do you have already
have a set of persistent BDE aliases?

BTW, you should consider using a TStringList rather than an array to store
the database paths.

V/R
Russell L. Smith

Quote
Melissa Mussitsch wrote in message <367F9B3A.DB32E...@ansys.com>...
>  DatabasePath := DBArray[i];
>  tempstring := ExtractFileName(DatabasePath);
>  AliasName := Copy(tempstring,1,Pos('.', tempstring)-1);
>  dmJobTrack.db.Connected := False;
>  dmJobTrack.db.AliasName := AliasName;
>  dmJobTrack.db.DatabaseName := 'db';
>  try
>   dmJobTrack.db.Connected := True;
>  except
>   showmessage('Error');
>  end;
>  dmJobTrack.db.Connected := False;

Re:Problem connecting to multiple databases ...


At this point I already have the BDE aliases.  I'll look into the TStringList
though, thanks.

Melissa

Quote
Russell L. Smith wrote:
> I might be missing something, but where to you set the TDatabase.Params PATH
> to use the database path extracted from DBArray?  Or do you have already
> have a set of persistent BDE aliases?

> BTW, you should consider using a TStringList rather than an array to store
> the database paths.

> V/R
> Russell L. Smith

> Melissa Mussitsch wrote in message <367F9B3A.DB32E...@ansys.com>...
> >  DatabasePath := DBArray[i];
> >  tempstring := ExtractFileName(DatabasePath);
> >  AliasName := Copy(tempstring,1,Pos('.', tempstring)-1);
> >  dmJobTrack.db.Connected := False;
> >  dmJobTrack.db.AliasName := AliasName;
> >  dmJobTrack.db.DatabaseName := 'db';
> >  try
> >   dmJobTrack.db.Connected := True;
> >  except
> >   showmessage('Error');
> >  end;
> >  dmJobTrack.db.Connected := False;

Re:Problem connecting to multiple databases ...


Hi - I'm sorry to bother you again.  But I did try the TStringList type.  It is
easy to switch the code over to do the same thing, but for some reason I must be
missing something simple.  I get an Access Violation on the first statement
involving the TStringList.  Is there something I need to do to create or
instantiate it?  I start of just by setting the Capacity and issuing a Clear.  I
immediately get an access violation.  I could not find any documentation stating
so.

Thanks!!
Melissa

Quote
Russell L. Smith wrote:
> I might be missing something, but where to you set the TDatabase.Params PATH
> to use the database path extracted from DBArray?  Or do you have already
> have a set of persistent BDE aliases?

> BTW, you should consider using a TStringList rather than an array to store
> the database paths.

> V/R
> Russell L. Smith

> Melissa Mussitsch wrote in message <367F9B3A.DB32E...@ansys.com>...
> >  DatabasePath := DBArray[i];
> >  tempstring := ExtractFileName(DatabasePath);
> >  AliasName := Copy(tempstring,1,Pos('.', tempstring)-1);
> >  dmJobTrack.db.Connected := False;
> >  dmJobTrack.db.AliasName := AliasName;
> >  dmJobTrack.db.DatabaseName := 'db';
> >  try
> >   dmJobTrack.db.Connected := True;
> >  except
> >   showmessage('Error');
> >  end;
> >  dmJobTrack.db.Connected := False;

Re:Problem connecting to multiple databases ...


Did you create the TStringList?  Any object needs to be created prior to
use.  Post a code sample that demonstrates the error.  I don't know what you
are trying to do, but this example should work (untested, uncompiled):

var
  nDatabase: Integer;
  slDatabases: TStringList;
begin
  slDatabases := TStringList.Create;
  try
    Session.GetAliasNames(slDatabases);
    for nDatabase := 0 to slDatabases.Count - 1 do
    begin
      StatusBar.Panels[0].Text := slDatabases[nDatabase];
      StatusBar.Refresh;
      blah blah blah;
    end;
  finally
    slDatabases.Free
  end;
end;

V/R
Russell L. Smith

Quote
Melissa Mussitsch wrote in message <368113F1.84273...@ansys.com>...
>I get an Access Violation on the first statement
>involving the TStringList.  Is there something I need to do to create or
>instantiate it?  I start of just by setting the Capacity and issuing a
Clear.  I
>immediately get an access violation.  I could not find any documentation
stating
>so.

Re:Problem connecting to multiple databases ...


Thank you.  I wasn't creating properly.
It works now.

Melissa

Quote
Russell L. Smith wrote:
> Did you create the TStringList?  Any object needs to be created prior to
> use.  Post a code sample that demonstrates the error.  I don't know what you
> are trying to do, but this example should work (untested, uncompiled):

> var
>   nDatabase: Integer;
>   slDatabases: TStringList;
> begin
>   slDatabases := TStringList.Create;
>   try
>     Session.GetAliasNames(slDatabases);
>     for nDatabase := 0 to slDatabases.Count - 1 do
>     begin
>       StatusBar.Panels[0].Text := slDatabases[nDatabase];
>       StatusBar.Refresh;
>       blah blah blah;
>     end;
>   finally
>     slDatabases.Free
>   end;
> end;

> V/R
> Russell L. Smith

> Melissa Mussitsch wrote in message <368113F1.84273...@ansys.com>...
> >I get an Access Violation on the first statement
> >involving the TStringList.  Is there something I need to do to create or
> >instantiate it?  I start of just by setting the Capacity and issuing a
> Clear.  I
> >immediately get an access violation.  I could not find any documentation
> stating
> >so.

Other Threads