我现在程序连接后台数据库,后台数据库和程序不再一台机子。如果后台数据库连接失败就自动联机本机的sql2000数据库我用的是ado访问sql2000。现在问题是如何扑捉连接错误
我用这样但不行  if adoconnection.connected then
                begin
                   执行程序
                end
                else
                begin
                  showmessage('连接错误!‘)
                end;
为什么数据库停止也不会提示呢?如何捕捉错误呢?

解决方案 »

  1.   

    try
      ....
      adoconnection.connected:=true
      ....
    except
      处理错误
      ....
    end
      

  2.   

    showmessage('连接错误!‘)后面的两个符号你用的好像是中文标点啊!!!!!!!!!!
      

  3.   

    if adoconnection.connected then
                    begin
                       执行程序
                    end
                    else
                    begin
                      showmessage('连接错误!‘)//showmessage('连接错误!');
                    end;
      

  4.   

    一般用
    try
    .........
    except
    .......
    end
    捕捉
      

  5.   

    try
      ....
      adoconnection.connected:=true
      ....
    except
      处理错误
      ....
    end
    这个用法应该没问题!
      

  6.   

    if adoconnection.connected then
                    begin
                       执行程序
                    end
                    else
                    begin
                      showmessage('连接错误!‘)
                    end
                    end;
      

  7.   

    if adoconnection.connected then
                   begin
                       执行程序
                    end
               else begin
                    showmessage('连接错误!');
               end;
               end;
      

  8.   

    try
    .........
    except
     on e:exception do
      showmessage(e.magssage);//看看出什么错。  
    end
      

  9.   

    try
    .........
    except
     on e:exception do
      showmessage(e.magssage);//看看出什么错。  
    end