Delphi——ADO动态连接数据库
时间:2011-02-16 来源:ManLoveGirls
使用Adoconnection连接语句:
'Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=SQLSL;"User ID=sa;Password=123456;Data Source=XP-201102131952\GSQL'
Provider:SQLOLEDB.1 //所选驱动
Persist Sercurity Info =False; //安全选项
Initial Catalog= SQLSL;//要连接的数据库
User ID =sa //用户名
Password = 123456;//密码
Data SOurce=XP-201102131952\GSQL//要连接的数据源
//用windows NT验证的
Integrated Security=SSPI //不用用户名和密码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
try
ADOConnection1.ConnectionString :='Provider=SQLOLEDB.1;Integrated Security=SSPI;'+
'Persist Security Info=False;Initial Catalog=SQLSL;'+
'Data Source=XP-201102131952\GSQL';
ADOConnection1.Open();
ShowMessage('连接SQL2000成功');
except
ShowMessage('连接SQL2000不成功');
end;
end;
end.
相关阅读 更多 +