当数据库中有大量记录时,它会在vb.net中抛出错误“操作已被用户取消”

时间:2012-04-22 07:46:58

标签: vb.net db2

我想从DB2检索记录并在VB.net中的DataGridView中显示记录。如果记录数量较少,则可以正常工作。

但是如果数据库tabe有大量记录,则会抛出错误“操作已被用户取消”。 任何人都可以帮我取悦......

我的代码是

    Dim strSQL As String

    Dim myConn, myCommand, rs As Object

    DataGridView1.DataSource = Nothing
    rs = CreateObject("ADODB.Recordset")
    Const DB_CONNECT_STRING = "Provider=MSDASQL.1;Persist Security Info=False;User ID=cpa5k;Data Source=NP1;DSN=NP1;UID=user;PASSWORD=pass;SDSN=Default;HST=sysplex.com;PRT=4101;Initial Catalog=QA1MM;"
    myConn = CreateObject("ADODB.Connection")
    myCommand = CreateObject("ADODB.Command")
    myConn.Open(DB_CONNECT_STRING)
    myCommand.ActiveConnection = myConn
    strSQL = " query "
    rs.Open(strSQL, myConn)
    Dim myDA As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
    Dim myDS As DataSet = New DataSet
    myDA.Fill(myDS, rs, "MyTable")
    DataGridView1.DataSource = myDS.Tables(0)
    DataGridView1.Refresh()
    myConn.Close()

显示的错误信息是:

  

有关调用实时的详细信息,请参阅此消息的结尾   (JIT)调试而不是此对话框。

     

** * ** 异常文字 ** * **** System.Runtime.InteropServices.COMException(0x800A0E80):操作   已被用户取消。

     

at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object   o,键入objType,String name,Object [] args,String [] paramnames,   Boolean [] CopyBack,Boolean IgnoreReturn)
  在Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object   实例,类型类型,字符串成员名称,对象[]参数,字符串[]   ArgumentNames,Type [] TypeArguments,Boolean [] CopyBack,Boolean   IgnoreReturn)在WindowsApplication2.Form1.Button4_Click(对象   发件人,EventArgs e)
  在System.Windows.Forms.Control.OnClick(EventArgs e)
  在System.Windows.Forms.Button.OnClick(EventArgs e)
  在System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
  在System.Windows.Forms.Control.WmMouseUp(消息& m,MouseButtons   按钮,Int32点击)
  在System.Windows.Forms.Control.WndProc(Message& m)
  在System.Windows.Forms.ButtonBase.WndProc(Message& m)
  在System.Windows.Forms.Button.WndProc(Message& m)
  在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)   在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&   m)在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32)   msg,IntPtr wparam,IntPtr lparam)

我正在运行的查询是:

SELECT   A.MVNDR_NBR                     
       ,A.MER_DEPT_NBR                  
      ,C.BYO_NBR                       
      ,B.MKT_NBR                       
      ,D.SKU_NBR                       
        ,A.STR_NBR                       
        ,B.BU_ID                         
        ,COALESCE(D.MIN_EFF_OH_QTY,0)    
        ,COALESCE(D.TRGT_OH_QTY,0)       
        ,D.THRH_BUOM_QTY_PCT             
        ,COALESCE(E.OH_QTY,0)            
        ,COALESCE(E.CHG_OH_QTY,0)        
        ,COALESCE(E.OO_QTY,0)            
        ,E.SKU_VLCTY_CD                  
        ,D.LEAD_TM_DAYS                  
        ,D.REV_TM_DAYS_CNT               
        ,COALESCE(D.SFTY_STK_DAYS,0)     
         ,D.ADJ_ASW_QTY                      
         ,D.MAX_INV_QTY                      
         ,D.TOT_PLNG_OVRD_DAYS               
         ,COALESCE(D.MIN_OH_QTY_DAYS,0)      
         ,F.CURR_DSVC_TYP_CD                 
         ,G.CURR_RMETH_CD                    
         ,F.DCHNL_DC_NBR                     
         ,COALESCE(F.BUY_MIN_QTY,0)          
         ,F.BUY_UOM_QTY                      
         ,COALESCE(E.CORD_ALLOC_QTY,0)       
         ,COALESCE(E.CORD_RSVD_QTY,0)          FROM     PO_AUTO_HORD_STRMV A               
         ,STR                B               
         ,MKT                C               
         ,MVNDR_SKU_STR      F               
         ,SKU_STR_LIST       G                
        ,PO_AUTO_HORD_PARM  D                   LEFT     OUTER JOIN                            
         STRSK_OH_EOO       E                   ON       E.STR_NBR        = D.STR_NBR           AND      E.SKU_NBR        = D.SKU_NBR           WHERE    A.PO_WK_DAY_NBR  = 4   AND      A.EFF_BGN_DT    <= '2011-09-22' AND      A.EFF_END_DT     > '2011-09-22'        AND      D.STR_NBR        = A.STR_NBR           AND      D.MVNDR_NBR      = A.MVNDR_NBR         AND      D.MER_DEPT_NBR   = A.MER_DEPT_NBR      AND      B.STR_NBR        = A.STR_NBR           AND      B.STR_OPEN_DT <= '2011-09-22'       AND      C.MKT_NBR        = B.MKT_NBR           AND      F.MVNDR_NBR      = A.MVNDR_NBR         AND      F.MER_DEPT_NBR   = A.MER_DEPT_NBR      AND      F.SKU_NBR        = D.SKU_NBR            AND      F.STR_NBR        = D.STR_NBR            AND      G.SKU_NBR        = D.SKU_NBR            AND      G.STR_NBR   
= D.STR_NBR            AND      F.OK_TO_ORD_FLG  = 'Y'                  AND      G.SKU_STAT_CD IN (100, 200)             AND      G.SOS_IND    IN ('V','B')           AND      F.CURR_DSVC_TYP_CD IN (1, 3)           ORDER BY A.MVNDR_NBR                            
        ,C.BYO_NBR                              
        ,B.MKT_NBR                              
        ,F.DCHNL_DC_NBR                         
        ,F.CURR_DSVC_TYP_CD                     
        ,D.SKU_NBR                              
        ,A.STR_NBR                               WITH  UR

1 个答案:

答案 0 :(得分:0)

我们之前遇到过这个问题,解决方法是在DB2 Client配置中增加QUERYTIMEOUTINTERVAL设置(或设置为零 - 这可能会产生其他问题)。

(见http://www.ibm.com/developerworks/forums/message.jspa?messageID=13894231


BTW,HardCode是对的,当.NET提供(优越的,IMO)ADO.NET和OLEDB时,没有理由使用ADODB(特别是通过CreateObject和后期绑定!)。