代码见下面,当出现错误或者连接不到服务器上时,不出现我代码中的MESSAGEBOX,求解!  Try
    With ADOConnection1 do
    Begin
      Connected:= false;
      Provider:= 'SQLOLEDB.1';
      Properties['Data Source'].Value:= EdtSrvIP.Text; //服务器名
      Properties['Initial Catalog'].Value:='StuPrice'; //表名
      Properties['User ID'].Value:= EdtSrvLoginName.Text; //用户名
      Properties['password'].Value:= EdtSrvLoginPWD.Text; //密码
      LoginPrompt:= false;
      try
        Connected:=True;
        ConnSucc:=TRUE;
        Messagebox(handle,'恭喜您,测试连接成功!','测试连接',MB_OK+MB_ICONASTERISK);
        ADOConnection1.Connected:=False;
      except
        begin
          Application.MessageBox('连接远程数据库失败!','连接失败', MB_OK);
          exit;
        end;
      End;
    End;
  except
    begin
      Application.MessageBox('无法连结远程服务器!','连接失败', MB_OK);
      exit;
  end;
  //End;

解决方案 »

  1.   

    try
      code;
      try
        code;
      finally
        code;
      end;
    except
      code;
    end;
      

  2.   

    我现在改成这样的了,好像还是不行的!(去掉了上层的Try语句)
        With ADOConnection1 do
        Begin
          Connected:= false;
          Provider:= 'SQLOLEDB.1';
          Properties['Data Source'].Value:= EdtSrvIP.Text; //服务器名
          Properties['Initial Catalog'].Value:='StuPrice'; //表名
          Properties['User ID'].Value:= EdtSrvLoginName.Text; //用户名
          Properties['password'].Value:= EdtSrvLoginPWD.Text; //密码
          LoginPrompt:= false;
          try
            Begin
              Connected:=True;
              ConnSucc:=TRUE;
              Messagebox(handle,'恭喜您,测试连接成功!','测试连接',MB_OK+MB_ICONASTERISK);
              ADOConnection1.Connected:=False;
            End;
          except
            on Exception do    //参看资料说,用Exception能捕捉到底层消息的,好像不行
            begin
              Application.MessageBox('连接远程数据库失败!','连接失败', MB_OK);
              exit;
            end;
          End;
        End;