coder123
coder123

Reputation: 77

ConnectionString in Delphi?

I'm trying to set the ConnectionString for a ADOConnection on start. Currently I'm using this code:

ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\x.mdb;Persist Security Info=False;';

Only problem is, I get a "EOLeException with message 'Authentication Failed' when I compile (as well as Access Violation). I'm sure it can't be that difficult, since the connection string is copied straight out of the object inspector (which works perfect when entered normally in object inspector.). My code currently resides on FormCreate.

Any help would be appreciated!

Upvotes: 0

Views: 4580

Answers (2)

PhilW
PhilW

Reputation: 457

Well, if your ADOConnection is in a datamodule along with your other dataset components, you will see an Access Violation on connect if the MainForm is created before your datamodule.

This maybe not be the problem but it's easy to check.

To resolve go to the menu Project|Options and select 'Form' in the list. The 'Auto-create Forms' listbox gives the forms created on program load, and the order in which they are created. Select the datamodule entry and drag it to the top of the list.

Good luck.

Upvotes: 2

Ken White
Ken White

Reputation: 125620

If it's happening when you press run, it's happening at runtime, not compile-time. You're still providing very little information to use to try and help you.

Make sure you have debugging turned on (Project|Options|Compiler, check the debugging options). Set a breakpoint on the line that causes the exception. Press F9 to run your app. When the breakpoint occurs, put your mouse pointer over the ADOConnection1 variable. What does it tell you? Most likely, that the variable is nil, which means it hasn't been created yet.

You should avoid doing anything you don't have to in the FormCreate event. Anything that accesses items on the form should be done in FormShow instead, so that the form has time to be fully created first.

Upvotes: 2

Related Questions