2

I want to connect to a SQL Server using ZEOS components under Windows, compiler is LAZARUS.

Here is my function:

procedure ConnecttoDatabase(Servername, Databasename: String;
    aConnection: TZConnection); overload;
var
    DatabaseStr: String;
begin
    aConnection.Connected := False;

    aConnection.Database := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + Databasename  +'.mdb;Persist Security Info=False';
    aConnection.HostName := Servername;
    aConnection.Protocol := 'ado';

    aConnection.Connected := True;
end;

Execute this function I get an "EOLE Exception" error, I need help on the correct connection string

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user9044066
  • 107
  • 2
  • 11

2 Answers2

3

Your connection string is wrong. With it, you're trying to use the Jet OLEDB provider. If you are truly connecting to a Microsoft SQL Server database, you should be using the SQLOLEDB or SQL Native Client to connect. You can use the MS SQL Server section on Connectionstrings.com to get a proper connection string.

mirtheil
  • 8,952
  • 1
  • 30
  • 29
3

As mentioned by mirtheil your connection string is wrong.
An easy way to get a good connection string is by using an UDL file.

Simply create a text file with extension .UDL and then doubleclick on it from explorer. Now you get a window where you can choose from all installed drivers and choose/enter the values you need. You can click on test connectionto see if it works.
Once you get it working there, open this file in notepad and there will be a complete connectionstring.

GuidoG
  • 11,359
  • 6
  • 44
  • 79