delphi 在运行时连接SQL 2008

mefy6pfw  于 2022-11-04  发布在  其他
关注(0)|答案(2)|浏览(210)

我尝试在运行时使用DBExpress连接SQL Server 2008和 Delphi 2009,但它不工作。当我在设计时设置所有属性时,它工作正常,但在运行时,我得到“未知驱动程序:mssql”。代码如下:

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;

我已经将dbxmssiderdll包含在与我的应用程序相同的目录中,但无济于事。如有任何帮助,将不胜感激。
标记

gg58donl

gg58donl1#

试试看:

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;

结束;
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

有关详细信息,请参见http://docwiki.embarcadero.com/RADStudio/en/Setting_Up_TSQLConnection

xn1cxnb4

xn1cxnb42#

我在 Delphi 2007和MSSQL中遇到过这种情况。您可能需要更改DLL名称,以匹配您的Delphi/DBExpress版本中的MSSQL驱动程序版本。另外,我使用的是SQL身份验证(又名SSPI),而不是SQL用户名和密码:

FSQLConnection := TSQLConnection.Create(Self);
FSQLConnection.ConnectionName := 'MSSQLConnection';
FSQLConnection.DriverName := 'MSSQL';
FSQLConnection.GetDriverFunc := 'getSQLDriverMSSQL';
FSQLConnection.LibraryName := 'dbxmss30.dll';
FSQLConnection.VendorLib := 'oledb';
FSQLConnection.LoginPrompt:= False;

FSQLConnection.Params.Values['SchemaOverride'] := 'sa.dbo';
FSQLConnection.Params.Values['DriverName'] := 'MSSQL';
FSQLConnection.Params.Values['BlobSize'] := '-1';
FSQLConnection.Params.Values['ErrorResourceFile'] := '';
FSQLConnection.Params.Values['LocaleCode'] := '0000';
FSQLConnection.Params.Values['MSSQL TransIsolation'] := 'ReadCommited';
FSQLConnection.Params.Values['OS Authentication'] := 'True';
FSQLConnection.Params.Values['Prepare SQL'] := 'False';
FSQLConnection.Params.Values['HostName'] := 'MyServerName';
FSQLConnection.Params.Values['DataBase'] := 'MyDatabaseName';

相关问题