Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory containing .mdb

Status
Not open for further replies.

cpmasesa

Programmer
Oct 24, 2002
78
AE
hello,

am using ADO and Delphi6

How do i get the directory in which the database (.mdb) is in from a TADOConnection??

TIA
 
cpmasesa,

Here's one way to so it:

Code:
procedure TForm1.Button1Click(Sender: TObject);
var
   str : String;         // string processing area
   intLen,               // length of a string
   intPos  : Integer;    // position in a string
const
   k_NAME = 'SourceDB='; // Setting we're after.
   k_DELI = ';';         // Delimiter
begin

   str := ADOTable1.Connection.ConnectionString;

   // Trim the stuff before the setting we're after.
   intLen := length( str );
   intPos := pos( k_NAME, str );
   str := copy( str, intPos + length( k_NAME ), intLen );

   // Trim the stuff after the setting we're after.
   intPos := pos( k_DELI, str );
   str := copy( str, 1, intPos - 1);

   // Handle the result.
   showMessageFmt( '%s is located in %s.',
                   [ AdoTable1.TableName, str ] );
end;

Hope this helps...

-- Lance
 
Lance,

thought you should know.

I had to change your code slightly to get exactly waht i wanted

const
....
k_Name = 'Data Source='; //not SourceDB
k_Deli = ';';
sDatabase = 'eMRentals; //actual name of .mdb for the app
....
begin
.....
// Trim the stuff after the setting we're after.
intPos := pos( k_DELI, str );
str := copy( str, 1, intPos - length(sDatabase) - 1);
//above line gives me the directory that i am looking for
//note the added part ' - length(sDatabase)'
....

Thanks.

Just curious, there is no functions for extracting this info? ie name of .mdb file, directory the file is in, Access version, etc?

Cheers

Clemens
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top