DBExpress动态连接SQL-Server

procedure TForm1.Button1Click(Sender: TObject);
var
  theCNN : TSQLConnection;//定义连接,要引用 DB, SqlExpr
begin
  theCNN := TSQLConnection.Create(self);
  theCNN.LoginPrompt := False;//关闭登入窗口
  theCNN.Params.Clear;
  theCNN.DriverName:='MSSQL';
  theCNN.GetDriverFunc:='getSQLDriverMSSQL';
  theCNN.LibraryName:='dbexpmss.dll';
  theCNN.VendorLib:='oledb';
  //--------下面设置连接叁数-----------
  theCNN.Params.Append('SchemaOverride=sa.dbo');
  theCNN.Params.Append('DriverName=MSSQL');
  theCNN.Params.Append('HostName=LocalHost\MSSQL'); //这是我SQL_Server服务器名
  theCNN.Params.Append('DataBase=KinSunKTV'); //SQL_Server数据库名称
  theCNN.Params.Append('User_Name=sa');  //SQL_Server用户名
  theCNN.Params.Append('Password=kinsun');//SQL_Server密码
  theCNN.Params.Append('BlobSize=-1');
  theCNN.Params.Append('ErrorResourceFile= ');
  theCNN.Params.Append('LocaleCode=0000');
  theCNN.Params.Append('MSSQL TransIsolation=ReadCommited');
  theCNN.Params.Append('OS Authentication=False');
  theCNN.Open;
  ShowMessage('连接成功');
end;

猜你喜欢

转载自www.cnblogs.com/jijm123/p/10586770.html