利用SQLConnection动态连接数据库的方法
procedure TForm1.Button2Click(Sender: TObject);
begin
SQLConnection1.ConnectionName := 'MSSQLConnection';
SQLConnection1.Params.Clear;
SQLConnection1.Params.Add('DriverName=MSSQL');
SQLConnection1.Params.Add('HostName=192.168.21.110');
SQLConnection1.Params.Add('DataBase=zbdb');
SQLConnection1.Params.Add('User_Name=sa');
SQLConnection1.Params.Add('Password=futongsa');
SQLConnection1.Params.Add('Blobsize=-1');
SQLConnection1.GetDriverFunc := 'getSQLDriverMSSQL';
SQLConnection1.LibraryName := 'dbexpmss.dll';
SQLConnection1.VendorLib := 'oledb';
SQLConnection1.LoginPrompt := false;
SQLConnection1.Connected := false;
try
SQLConnection1.Connected := true;
showmessage('联接成功');
except
showmessage('联接失败');
end;
end;