Sql-server – DBExpress connecting SQL 2008 at runtime with Delphi 2009

dbexpressdelphidelphi-2009sql server

I'm trying to connect at runtime with SQL Server 2008 with Delphi 2009 using DBExpress, it it's not working. When I set all the properties at design time, it works great, but at RunTime, I'm getting "unknown driver: mssql". Below is the code:


  scnConexao := TSQLConnection.Create(nil);
  scnConexao.DriverName := 'MSSQL';
  scnConexao.ConnectionName := 'MSSQLConnection';
  scnConexao.GetDriverFunc := 'getSQLDriverMSSQL';
  scnConexao.LibraryName := 'dbxmss.dll';
  scnConexao.VendorLib := 'oledb';
  scnConexao.LoginPrompt := False;
  scnConexao.Params.Add('SchemaOverride=sa.dbo');
  scnConexao.Params.Add('HostName=DESKTOP');
  scnConexao.Params.Add('DataBase=DBNAME');
  scnConexao.Params.Add('OS Authentication=False');
  scnConexao.Params.Add('User_Name=UserName');
  scnConexao.Params.Add('Password=Password');
  scnConexao.Params.Add('MSSQL TransIsolation=ReadCommited');
  scnConexao.Open;

I have included the dbxmss.dll in the same directory as my app, but to no avail. Any help would be greatly appreciated.
Tks

Best Answer

Try this:

With MSSQLCONNECTION do begin
ConnectionName:= 'SQLCONN';
LoadParamsFromIniFile('file.ini');
try
Connected:=true;
Execute('select * from auto',nil);
except
  on E: Exception do begin
    ShowException(E, nil);
    Halt(1);
  end;
end;

end;

base.ini:

[SQLCQONN]
bad param
drivername=MSSQL
schemaoverride=%.dbo
vendorlibwin64=sqlncli10.dll
HostName=localhost\sqlexpress
database=sec
user_name=sa
password=Guess
blobsize=-1
localecode=0000
isolationlevel=ReadCommitted
os authentication=False

For details see http://docwiki.embarcadero.com/RADStudio/en/Setting_Up_TSQLConnection