放一個連接配接元件 ADOConnection 其它元件TADODataSet,TADOQuery等的connection指向ADOConnection就可以了.
function OpenADOConn:boolean;
begin
result:=false;
try
with ADOConnection do
begin
Connected:= false;
Provider:= 'SQLOLEDB.1';
Properties['Data Source'].Value:= HostName; //伺服器名
Properties['Initial Catalog'].Value:= DatabaseName; //表名
Properties['User ID'].Value:= UserID; //使用者名
Properties['password'].Value:= UserPWD; 密碼
LoginPrompt:= false;
try
Connected:= true;
except
begin
Application.MessageBox('無法連結遠端資料庫!'
,'注意', MB_OK);
exit;
end;
end;
end;
finally
end;
result:=true;
end;