delphi如何连接sql2000

来源:百度知道 编辑:UC知道 时间:2024/05/28 02:04:28
delphi如何连接sql2000,高手帮忙写个例子

function checkconnect(s:string;ADOcon:TADOConnection):boolean;
begin
ADOcon:=TADOConnection.Create(nil);
ADOcon.ConnectionString:='';
ADOcon.Connected:=False;
ADOcon.LoginPrompt:=False;
ADOcon.ConnectionString:=s;
try
ADOcon.Connected:=True;
ADOcon.Free;
result:=True;
except
ADOcon.Free;
result:=False
end;
end;

procedure TForm1.G1Click(Sender: TObject);
begin
if checkconnect('Provider=SQLOLEDB.1;'+'Password='+edit2.Text+';Persist Security Info=True;'
+'User ID='+edit3.Text+';Initial Catalog='+edit4.Text+';'+'Data Source='+edit1.Text,ADOConnection1) then
Application.MessageBox('数据库连接成功!'
,'提示', 64)
else Application.MessageBox('数据库连接失败!请检查数据库连接信息是否填写正确!','警告',16);
end;

adoconMain.ConnectionString:='';
if pw<>'' then
adoconM