初始化TSQLConnection驱动程序非GUI应用程序

时间:2016-12-14 11:43:45

标签: sql-server-2008 delphi database-connection

我试图在非GUI应用程序的运行时创建TSQLConnection

Uses Data.DB, Data.SqlExpr, Data.DBXMSSQL; 
...
procedure TFoo.InitializeDB;
begin
  if NOT Assigned(SQLCon) then exit;
  SQLCon.Params.Clear;
  SQLCon.ConnectionName := 'ReportsCon';
  SQLCon.DriverName     := 'MSSQL';
  SQLCon.LoadParamsFromIniFile('C:\ConfigTest\DBTest.ini');
  try
    SQLCon.Connected      := True;
  except
    on E: Exception Do
      LastErr := E.Message;
  end;
end;

我收到了这个错误

DBX Error:  Driver could not be properly initialized.  Client library may be missing, not installed properly, of the wrong version, or the driver may be missing from the system path.

出于测试目的,我创建了一个新的GUI项目,我将TButton放在表单上,​​其中包含以下OnClick事件

Uses Data.DB, Data.SqlExpr, Data.DBXMSSQL;
...
procedure TForm12.btn1Click(Sender: TObject);
var
  SQLConnection: TSQLConnection;
begin
  SQLConnection := TSQLConnection.Create(nil);
  try
    SQLConnection.ConnectionName := 'ReportsCon';
    SQLConnection.DriverName     := 'MSSQL';
    SQLConnection.LoadParamsFromIniFile('C:\ConfigTest\DBTest.ini');
    try
      SQLConnection.Connected      := True;
    except
      on E: Exception Do
        ShowMessage(E.Message);
    end;
  finally
    SQLConnection.Free;
  end;
end;

代码按预期运行且没有错误。

EXE和dbxmss.dll都在同一个文件夹

C:\Users\$Name\Documents\Embarcadero\Studio\Projects\Win32\Debug

我在这里缺少什么?

0 个答案:

没有答案