用ADO连接数据库,如何捕获连接失败的错误!如何处理。

解决方案 »

  1.   

    if adoconnection.connect then 
    ..
    else
    ..
      

  2.   

    onInfoMessage错误包括:
      Error = interface(IDispatch)
        ['{00000500-0000-0010-8000-00AA006D2EA4}']
        function Get_Number: Integer; safecall;
        function Get_Source: WideString; safecall;
        function Get_Description: WideString; safecall;
        function Get_HelpFile: WideString; safecall;
        function Get_HelpContext: Integer; safecall;
        function Get_SQLState: WideString; safecall;
        function Get_NativeError: Integer; safecall;
        property Number: Integer read Get_Number;
        property Source: WideString read Get_Source;
        property Description: WideString read Get_Description;
        property HelpFile: WideString read Get_HelpFile;
        property HelpContext: Integer read Get_HelpContext;
        property SQLState: WideString read Get_SQLState;
        property NativeError: Integer read Get_NativeError;还有事件状态:TEventStatus
      

  3.   

    try
      //连接数据库
    except
    on E:EOleException do
    begin
      //异常
    end;
      

  4.   

    try 
      adotable1.connection
    except on E:EOleException do
    begin
    //处理
    end;
      

  5.   

    tryexcept on e: do
    begin
    end就是这样捕获特定的数据库异常!!
      

  6.   

    try
      ADOConnection1.Connected 
    execpt on EDataBaseError do
      showmessage('数据库链接错误');
    end;