How To Select Another DataSet With TADOConnection String

jsmitter
jsmitter used Ask the Experts™
on
I would like to set the the ADO Connect location of my Access dB file from within the Form Create procedure. I think I'm close, but no cigar

ADOConnection1.ConnectionString := '\\Monitor1\Sec\Hawt.mdb'
                                                                             +';Provider=Microsoft.Jet.OLEDB.4.0';

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
If the db is on local drive use:

{Office 2007} ADOConnection1.ConnectionString:='Microsoft.ACE.OLEDB.12.0;Data Source=C:\Monitor1\Sec\Hawt.accdb;Persist Security Info=False';

{Office 2003} ADOConnection1.ConnectionString:='Microsoft.Jet.OLEDB.4.0;Data Source=C:\Monitor1\Sec\Hawt.mdb;Persist Security Info=False';

else for network drive:

{Office 2007} ADOConnection1.ConnectionString:='Microsoft.ACE.OLEDB.12.0;Data Source=//Monitor1/Sec/Hawt.accdb;Persist Security Info=False';

{Office 2003} ADOConnection1.ConnectionString:='Microsoft.Jet.OLEDB.4.0;Data Source=//Monitor1/Sec/Hawt.mdb;Persist Security Info=False';

Regards,
B.

jsmitterSenior Project Engineer

Author

Commented:
Thanks. Now it compiles. However, I get a 'could not find installable ISAM' message after it compiles. This happens for both local and network access of the mdb file. Here's my code for the local access-
ADOConnection1.ConnectionString:=
  'Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\All Users\Documents\Sec\Hawt.mdb;Persist Security Info=False';
 
ADOConnection1.Connected:= True;
.
.
.
 
jsmitterSenior Project Engineer

Author

Commented:
Here's all the code (to connect to the local pc) I'm trying to execute that generates the 'could not find installable ISAM' message. It's ececuted by my 'Form.Create' procedure.
ADOConnection1.ConnectionString:='Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\All Users\Documents\Security\Hawt.mdb;Persist Security Info=False';
 ADOConnection1.Connected:= True;
 ADOTable1.Connection.Connected:= True;
 ADOTable1.Active:= True;
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Commented:
You are missing the word "Provider" in the connection string, try this way:

ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\All Users\Documents\Sec\Hawt.mdb;Persist Security Info=False';

If you are still getting the message then download the latest Microsoft Jet Drivers
http://support.microsoft.com/kb/239114

for Windows XP
http://download.microsoft.com/download/a/d/f/adfdf363-0b09-4f39-bf89-1b4bc234fe97/windowsxp-kb829558-x86-enu.exe

for Windows Server 2003
http://download.microsoft.com/download/a/a/c/aacdba68-214d-484c-b8ac-164fe7261668/windowsserver2003-kb829558-x86-enu.exe

for Microsoft Windows 2000
http://download.microsoft.com/download/9/d/c/9dcd9e1c-badc-4fe4-a52e-8f2fdfb652db/windows2000-kb829558-x86-enu.exe

for Microsoft Windows 95, Microsoft Windows 98, or Microsoft Windows NT 4.0
http://download.microsoft.com/download/4/3/9/4393c9ac-e69e-458d-9f6d-2fe191c51469/jet40sp8_9xnt.exe

for Microsoft Windows Millennium Edition
http://download.microsoft.com/download/5/d/5/5d5f0a95-09af-4a88-9276-9fa47b9d522e/jet40sp8_wme.exe

Regards,
B.
Commented:
This should be enough:

ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\All Users\Documents\Security\Hawt.mdb;Persist Security Info=False';
ADOConnection1.Connected:= True;
ADOTable1.Active:= True;

Commented:
Hi,
   there is a great function in Delphi that let's you build this string with the standard ADO user interface. Use the code below:

Uses AdoConEd;

procedure TForm1.Button1Click(Sender: TObject);
begin
 if EditConnectionString(ADOConnection1) then
  ShowMessage(ADOConnection1.ConnectionString);
end;

In this way you can get the correct syntax of any connection string and embed it into your code, or beter, call this function the first time the app runs, set the parameters in the ADO UI and then store it in a ini file...

Commented:
Hi again,
  you can also use the Test Connection button to test the connection to your DB..
jsmitterSenior Project Engineer

Author

Commented:
It's working. Thanks for the help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial