Peter Kiers
asked on
Change the path to the connection of my database.
Dear Experts,
I have a programm that has a connection to a Access-database.
I have used the ADOConnection1 and the ADOQuery1-components.
Everything works fine.
This what I have as connection string property:
provider=microsoft.jet.OLE DB.4.0;Dat a Source=C:\Users\Brandon\Do cuments\My Project\te st,mdb;Per sist Security info=false
and I want it change to this:
provider=Microsoft.Jet.OLE DB.4.0;Per sist Security Info=False;Data Source='+IncludeTrailingPa thDelimite r(ExtractF ilePath(Ap plication. ExeName))+ 'Database. pkd;';
But where do i have to put it?
Greetings, Peter Kiers
I have a programm that has a connection to a Access-database.
I have used the ADOConnection1 and the ADOQuery1-components.
Everything works fine.
This what I have as connection string property:
provider=microsoft.jet.OLE
and I want it change to this:
provider=Microsoft.Jet.OLE
But where do i have to put it?
Greetings, Peter Kiers
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
"is this line correct?"
Normally I do just fine without "includingtrailingpathdeli miter"
So try this:
ADOConnection1 := 'provider=Microsoft.Jet.OL EDB.4.0;Pe rsist Security Info=False;Data Source=' + ExtractFilePath(Applicatio n.ExeName) + 'test.mdb';
Normally I do just fine without "includingtrailingpathdeli
So try this:
ADOConnection1 := 'provider=Microsoft.Jet.OL
I left out "ConnectionString".
Now I forget whether you need to put the \ slash in it or not.
Do yourself a favour and debug this one yourself (because it's fun).
Put a showmessage:
ADOConnection1.ConnectionS tring := 'provider=Microsoft.Jet.OL EDB.4.0;Pe rsist Security Info=False;Data Source=' + ExtractFilePath(Applicatio n.ExeName) + 'test.mdb';
Showmessage(ADOCinnection1 .Connectio nString);
If it shows C:\Users\Brandon\Documents \MyProject test.mdb
then you know you need to add a '\' to 'test.mdb;
Now I forget whether you need to put the \ slash in it or not.
Do yourself a favour and debug this one yourself (because it's fun).
Put a showmessage:
ADOConnection1.ConnectionS
Showmessage(ADOCinnection1
If it shows C:\Users\Brandon\Documents
then you know you need to add a '\' to 'test.mdb;
For example on form create, note that you can not change connection string on AdoConnection1 that is already connected, so you need to disconnect, change and reconnect this way, then later you can execute queries or open tables that are associated with AdoConnection1 (or use the name of your connection)
procedure TForm1.FormCreate(Sender: TObject);
begin
ADOConnection1.Connected:= False;
ADOConnection1.ConnectionS tring:='pr ovider=Mic rosoft.Jet .OLEDB.4.0 ;Persist Security Info=False;Data Source='+IncludeTrailingPa thDelimite r(ExtractF ilePath(Ap plication. ExeName))+ 'Database. pkd;';
ADOConnection1.Connected:= True;
end;
Regards,
B.
procedure TForm1.FormCreate(Sender: TObject);
begin
ADOConnection1.Connected:=
ADOConnection1.ConnectionS
ADOConnection1.Connected:=
end;
Regards,
B.
Ups, again something similar was posted during the time I was typing, I should take touch typing classes :)
ASKER
I have this:
procedure TForm1.FormCreate(Sender: TObject);
begin
ADOConnection1.Connected:= False;
ADOConnection1.ConnectionS tring:='pr ovider=Mic rosoft.Jet .OLEDB.4.0 ;Persist Security Info=False;Data Source='+IncludeTrailingPa thDelimite r(ITKnowle dgeBase.ex e))+'test. mdb;';
ADOConnection1.Connected:= True;
end;
In the (Application.ExeName))-par t I have put:
ITKnowledgeBase.EXE
But i get undeclared identifier: 'ITKnowledgeBase'
procedure TForm1.FormCreate(Sender: TObject);
begin
ADOConnection1.Connected:=
ADOConnection1.ConnectionS
ADOConnection1.Connected:=
end;
In the (Application.ExeName))-par
ITKnowledgeBase.EXE
But i get undeclared identifier: 'ITKnowledgeBase'
No no no, where it says 'Application.Exename' don't replace it with your application's exename, leave it exactly as it is
By the way, ExtractFilePath uses SysUtils, just in case you didn't add it to your uses list
By the way, ExtractFilePath uses SysUtils, just in case you didn't add it to your uses list
ASKER
I forgot something to put in the OnCreate -event:
procedure TForm1.FormCreate(Sender: TObject);
begin
ADOConnection1.Connected:= False;
ADOConnection1.ConnectionS tring:='pr ovider=Mic rosoft.Jet .OLEDB.4.0 ;Persist Security Info=False;Data Source='+IncludeTrailingPa thDelimite r(ExtractF ilePath(IT KnowledgeB ase.exe))+ 'test.mdb; ';
ADOConnection1.Connected:= True;
end;
Greetings, PK
procedure TForm1.FormCreate(Sender: TObject);
begin
ADOConnection1.Connected:=
ADOConnection1.ConnectionS
ADOConnection1.Connected:=
end;
Greetings, PK
Application.exename is actually a full application path+name, it shouldn't be changed...proper format is:
IncludeTrailingPathDelimit er(Extract FilePath(A pplication .ExeName))
Or translated into ordinary language extract the file path [ExtractFilePath] of my application [Application.ExeName] and use the backslash on the end [IncludeTrailingPathDelimi ter].
(Or at least I think that is the meaning :))
IncludeTrailingPathDelimit
Or translated into ordinary language extract the file path [ExtractFilePath] of my application [Application.ExeName] and use the backslash on the end [IncludeTrailingPathDelimi
(Or at least I think that is the meaning :))
Make it a string and remove a parenthesis
IncludeTrailingPathDelimit er("ITKnow ledgeBase. exe")+
IncludeTrailingPathDelimit
Never mind my last, not paying attention...
ASKER
It works. One little question, the connectionstring line is a very long line
where can I break the line. Is this possible?
where can I break the line. Is this possible?
It is not possible because it needs one single string. However, you can always put line breaks in your source code like this:
ADOConnection1.ConnectionS tring := 'This is an example' +
' of multiple lines ' +
'of text';
..which will add up to 'This is an example of multiple lines of text'
ADOConnection1.ConnectionS
' of multiple lines ' +
'of text';
..which will add up to 'This is an example of multiple lines of text'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I modified your solution and I haven't noticed that I copied ITKnowledgeBase.exe instead of application.exename
Please change
conn_str:=conn_str+Include TrailingPa thDelimite r(ExtractF ilePath(IT KnowledgeB ase.exe));
with
conn_str:=conn_str+Include TrailingPa thDelimite r(ExtractF ilePath(Ap plication. Exename));
Please change
conn_str:=conn_str+Include
with
conn_str:=conn_str+Include
ASKER
provider=Microsoft.Jet.OLE
is this line correct?