一个很简单的连接程序..可是每次连接不成功时.也就是运行到application.Terminate;电脑就狂叫很久...,这是为什么呢...function TfrmMain.MainDBconnect: boolean;
var
DBconnectstring:string;
// servername,databasename,username,password:string;
begin
result:=true;
adoconnection1.Connected:=false;
adoconnection1.ConnectionString:='';
adoconnection1.ConnectionString:='FILE NAME='+extractfilepath(application.ExeName)+'\Dbconnect.udl';
try
adoconnection1.Connected:=true;
except
adoconnection1.Close;
messagebox(Handle,'连接数据库服务器没有成功,请重新设置连接参数!','错误',Mb_IconInformation+Mb_OK);
result:=false;
end;
end;procedure TfrmMain.FormCreate(Sender: TObject);
if not MainDBconnect then
begin
messagebox(Handle,'连接数据失败,请重新设置目录下的DBconnect.udl文件!','提示',Mb_Iconinformation+Mb_OK); application.Terminate;
end;
end;
var
DBconnectstring:string;
// servername,databasename,username,password:string;
begin
result:=true;
adoconnection1.Connected:=false;
adoconnection1.ConnectionString:='';
adoconnection1.ConnectionString:='FILE NAME='+extractfilepath(application.ExeName)+'\Dbconnect.udl';
try
adoconnection1.Connected:=true;
except
adoconnection1.Close;
messagebox(Handle,'连接数据库服务器没有成功,请重新设置连接参数!','错误',Mb_IconInformation+Mb_OK);
result:=false;
end;
end;procedure TfrmMain.FormCreate(Sender: TObject);
if not MainDBconnect then
begin
messagebox(Handle,'连接数据失败,请重新设置目录下的DBconnect.udl文件!','提示',Mb_Iconinformation+Mb_OK); application.Terminate;
end;
end;
var
DBconnectstring:string;
// servername,databasename,username,password:string;
begin
result:=true;
adoconnection1.Connected:=false;
adoconnection1.ConnectionString:='';
adoconnection1.ConnectionString:='FILE NAME='+extractfilepath(application.ExeName)+'\Dbconnect.udl';
///////////////////加上下边的
{ADOConnection1.Provider := 'FILE NAME='+extractfilepath(application.ExeName)+'\Dbconnect.udl';} try
adoconnection1.Connected:=true;
except
adoconnection1.Close;
messagebox(Handle,'连接数据库服务器没有成功,请重新设置连接参数!','错误',Mb_IconInformation+Mb_OK);
result:=false;
end;
end;
试过了,还是狂叫...听得晕死了...
怎么回事啊..
begin
if Connected then
Connected := False;
Provider := 'FILE NAME=' + ExtractFilePath(Application.ExeName) + 'Link.udl';
ConnectionString := 'FILE NAME=' + ExtractFilePath(Application.ExeName) + 'Link.udl';
Connected := True;
end;你改一下
'FILE NAME='+extractfilepath(application.ExeName)+'Dbconnect.udl';你:ShowMessage('FILE NAME='+extractfilepath(application.ExeName)+'\Dbconnect.udl')
看看是什么结果?
多了个“\”
我上面的源程序如果udl文件中参数设置正常..然后连接是可以
正常运行程,显示数据库..
而我刚才是故意把参数设置错误,也就是不能连接的情况..
按程序所写,,它应当是程序会退出...
而现在的情况是,程序退出之后,就做死的叫...
Exit;//加上
直接 Exit;
Application.OnIdle := nil; // 以后不再响应了