با سلام
من در زمان اتصال به SQL بر روی شبکه از کد زیر برای نمایش پیغام مناسب در صورت بروز خطا استفاده میکنم، امیدوارم جالب و کاربردی باشه.
Try
DM_Main.ADOConnection.Connected:=True;
except on E: Exception do
begin
StatusBar_Main.Panels[2].Text := 'Failed Connect to DataBase in ' + Str_Server ;
str_Temp := E.Message ;
Str_Error:='';
If Pos('SQL Server does not exist or access denied',str_Temp)> 0 Then Str_Error :='SQLServer_Not_Find';
If Pos('Login failed for user',str_Temp)> 0 Then Str_Error :='Invalid_UserName';
If Pos('Cannot open database requested in login',str_Temp)> 0 Then Str_Error :='DataBase_Not_Find';
If Pos('Timeout expired',str_Temp)> 0 Then Str_Error :='SQL_Timeout_expired';
MessageDlg( #13+#13 + Str_Error + #13+#13 , mtWarning , [mbOK], 0);
end;
end;
با تشکر