try
myinifile:=tinifile.Create(filename);
con_server:= myinifile.ReadString('database connect','servername','') ;
con_user:= myinifile.readString('database connect','user name','');
con_pass:= myinifile.readString('database connect','password','');
con_database:= myinifile.readString('database connect','databasename','');
self.data_con.ConnectionString:=format('Provider=SQLOLEDB.1;Password=%s;Persist Security Info=false;User ID=%s;Initial Catalog=%s;Data Source=%s;Connect Timeout=3;',[con_pass,con_user,con_database,con_server]);
data_con.LoginPrompt:=false;
data_con.Connected:=true;
except
showmessage('数据库连接错误!');
myinifile.Free;
pubunit.openform(tfrm_datacon,frm_datacon,'数据库连接向导'); end; 编绎时语法没有报错,问题在执行时:当con_pass,con_user,con_database,con_server 正确无误时运行正常,当con_pass,con_user,con_database,con_server 有错误时,则程序长时间没有反应。
我想让它在连数据库时的连接时间设为5秒钟,若5秒钟还未连接到数据则提示。请问要如何做????
myinifile:=tinifile.Create(filename);
con_server:= myinifile.ReadString('database connect','servername','') ;
con_user:= myinifile.readString('database connect','user name','');
con_pass:= myinifile.readString('database connect','password','');
con_database:= myinifile.readString('database connect','databasename','');
self.data_con.ConnectionString:=format('Provider=SQLOLEDB.1;Password=%s;Persist Security Info=false;User ID=%s;Initial Catalog=%s;Data Source=%s;Connect Timeout=3;',[con_pass,con_user,con_database,con_server]);
data_con.LoginPrompt:=false;
data_con.Connected:=true;
except
showmessage('数据库连接错误!');
myinifile.Free;
pubunit.openform(tfrm_datacon,frm_datacon,'数据库连接向导'); end; 编绎时语法没有报错,问题在执行时:当con_pass,con_user,con_database,con_server 正确无误时运行正常,当con_pass,con_user,con_database,con_server 有错误时,则程序长时间没有反应。
我想让它在连数据库时的连接时间设为5秒钟,若5秒钟还未连接到数据则提示。请问要如何做????
var
regcode: TRegistry;
cnnString,Server,user,password1,database: string;
modal:TRegdbFrm;
begin
with dmdata.adocnn do
begin
connected:= false;
try
regcode:= TRegistry.Create;
regcode.RootKey:= HKEY_LOCAL_MACHINE;
if regcode.OpenKey('SoftWare\Twaysoft',false) then
begin
Server:= regcode.ReadString('Server');
User:= regcode.ReadString('User');
password1:= password_out(regcode.ReadString('password'));
database:= regcode.ReadString('database');
regcode.CloseKey;
regcode.Free;
end;
cnnString:='Provider=SQLOLEDB.1;Password='+password1
+';Persist Security Info=True;User ID='+user+';Data Source='+server
+';Initial Catalog='+database+';';
ConnectionString:=cnnString;
LoginPrompt:=False;
Connected:=True;
//open;
except
on e:exception do
begin
ShowMessage('数据连接失败!' +e.Message);
modal:= TregdbFrm.Create(application);
begin
Try
modal.ShowModal;
finally
modal.Free;
end;
end;
end;
end;
end;
end;