我在win98下用delphi7程序连接sqlserver2000个人版程序:ADOConnection1.Open;如果sqlserver2000没有启动,则程序执行连接失败,系统弹出一个SQL错误后便出现没完没了的"该程序执行了非法操作即将关闭"窗口,这个窗口总也关闭不了,除非强行关机!后来用这段程序试图由程序捕获连接错误,结果毫无作用,仍如上所述,没完没了的恶心窗口!
try
ADOConnection1.Open;
except
ON E:EDatabaseError do begin
ShowMessage('无法连接到数据库!');
exit;
end;
end;请大家帮帮我!
try
ADOConnection1.Open;
except
ON E:EDatabaseError do begin
ShowMessage('无法连接到数据库!');
exit;
end;
end;请大家帮帮我!
ADOConnection1.Open;
except
ShowMessage('无法连接到数据库!');
exit;
end;
end;
就行了。————————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
————————————————————————————————————
确实可以捕获到连接失败了!但这时关闭窗口的话仍出现没完没了的"该程序执行了非法操作即将关闭"窗口, 如果是连接成功或根本不执行adoconnect连接,则不会出现这种令人讨厌的窗口, 问题似乎出现在ADO连接且失败这种情况下, 应该如何避免出现这种系统关闭窗口???
if you are sure of that the connecting is the reason, please hava a try like this:
try
ADOConnection1.Open;
except
ShowMessage('无法连接到数据库!');
ADOConnection1.Close;
Exit;
end;// (Swayi.F)
ADOConnection1.Open;
except
// ShowMessage('无法连接到数据库!');
ADOConnection1.Close;
ADOConnection1.free;
halt;
end;
看来还是bde好用点?
DataModule1.ADOConnection1.ConnectionString:= GetConnectionString;
DataModule1.ADOConnection1.Connected:= true;
except
on e:exception do
begin
MessageBox(Application.Handle,Pchar('数据库初始化设置错误,请与系统管理员联系!' + char(13) + string(e.Message)),'错误',MB_OK OR MB_ICONSTOP);
Exit;//如果这个代码写在.DPR文件,你的程序就可以正常退出了!
end;
end;你在打开数据库连接的时候用我上面的代码看看,你就知道你的数据库为什么错误了!