在运行时连接 SQL 2008

发布于 2024-09-03 02:43:05 字数 870 浏览 6 评论 0原文

我试图在运行时使用 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;

我已将 dbxmss.dll 包含在与我的应用程序相同的目录中,但无济于事。任何帮助将不胜感激。
塔克斯

I'm trying to connect at runtime with SQL Server 2008 with Delphi 2009 using DBExpress, 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒与心事 2024-09-10 02:43:05

试试这个:

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< /a>

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

空袭的梦i 2024-09-10 02:43:05

我很幸运地使用了 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';

I've had luck with Delphi 2007 and MSSQL with this. You might need to change the DLL name to match the version of the MSSQL driver that is in your version of Delphi/DBExpress. Also, I am using SQL Authentication (aka SSPI) instead of a SQL username and password:

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';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文