2,495
社区成员
发帖
与我相关
我的任务
分享
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;