aspTest是个TADOStoredProc组件,与其他TADOStoredProc组件使用一个TADOConnection,下面两个语句连在一起,第二条语句当条件成立时出错,有可能是什么问题呢?if aspTest.State <> dsInactive then aspTest.Close;
if aspTest.Connection.Connected then aspTeslt.Connection.Close;

解决方案 »

  1.   

    多了一个字母,应该是:if aspTest.State <> dsInactive then aspTest.Close;
    if aspTest.Connection.Connected then aspTest.Connection.Close;
    请问什么情况下第二条语句出错呢?
      

  2.   

    if aspTest.State <> dsInactive then aspTest.Close;
    if aspTest.Connection.Connected then 
       aspTest.Connection.Connected:=false;
      

  3.   

    问题是当条件成立时出错,就是说aspTest.Connection.Close出错,不是代码和语法问题,是在什么情况下close会出错的问题。这个语句有时不出错,程序转了一圈回来就在这里出错了。调试时显示在执行到"c:\program files\borland\delphi6\source\vcl\DB.pas"中的
    procedure TCustomConnection.Close;
    begin
     SetConnected(False);
    end;
    时出现下面错误信息:Project Test_Query.exe raised exception class EAccessViolation with message 'Access violation at address 0051E082 in module 'Test_Query.exe'. Read of address 00000000'. Process stopped. Use Step Run to continue.
    这条语句本身没有错误,但总是由它触发了错误,真是头痛。
      

  4.   

    可能是必须所有使用同一Connection的ADO组件都关闭了才可以关闭Connection吧?我干脆把这一句去了,就没问题了。
      

  5.   

    是的,当其它组件没断开与connection的连接而要关闭connection,肯定是要出错的了.