给你一个东西看看就行了
if not ado.Connected then
begin
s:=extractfilepath(application.ExeName);
ti:=tinifile.Create(s+'zhxuf.ini');
try
try
begin
s:=ti.ReadString('database','liangjie','');
ado.ConnectionString:=s;
ado.Connected:=true ;
end;
except
while not ado.Connected do
try
if not ado.Connected then
begin
s:=PromptDataSource(0,'');
ado.ConnectionString:=s;
ado.Connected:=true;
ti.WriteString('database','liangjie',s);
end;
except
if application.MessageBox('数据库连接错误,是否继续连接?','系统提示:',mb_yesno)=idno then
application.Terminate;
end;
end;
finally
ti.Free;
end;
end;
end;