即使在设置cmd.CommandTimeout = 0后,我也收到超时过期错误 查询从SAP数据库中提取,在SAP中,sql查询运行正常,但是当我尝试在visual studio中的适配器上运行它时,我得到了Timeout Expired错误。 有什么我想念的吗? 如何延长超时时间以便我的查询可以运行? 这是我的VB.Net代码:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim ds As New DataSet
Dim dv As New DataView
Dim ConStr As String = "Data Source= .\SQLOLEDB.1;Password=Password;Persist Security Info=True;User ID=User;Initial Catalog=XXX;Data Source=xxx.xxx.x.x;Connection Timeout=0"
Dim cn As SqlConnection
Try
cn = New SqlConnection(ConStr)
cn.Open()
Dim cmd = cn.CreateCommand()
cmd.CommandTimeout = 0
Dim ad As New SqlDataAdapter("/* SELECT FROM [dbo].[OITM] T2 */" &
" DECLARE @Whs_From AS VARCHAR(10)" &
" DECLARE @Whs_To AS VARCHAR(10)" &
"/* WHERE */" &
" SET @Whs_From = /* T2.DfltWH */ 'AUT-L-N'" &
" SET @Whs_To = /* T2.DfltWH */ 'AUT-L-N'" &
" SELECT QUT1.[ItemCode] AS 'Code'," &
" ISNULL(SUM(QUT1.[OpenQty]), 0) AS 'Open'" &
" INTO #QuoteSum" &
" FROM QUT1 QUT1 INNER JOIN OITM OITM ON QUT1.[ItemCode] = OITM.[ItemCode] INNER JOIN OQUT OQUT ON QUT1.[DocEntry] = OQUT.[DocEntry]" &
" WHERE QUT1.[WhsCode] = OITM.[DfltWH] AND QUT1.[LineStatus] = 'O' AND OQUT.[Canceled] != 'Y' GROUP BY QUT1.[ItemCode]" &
" SELECT QUT1.[ItemCode] AS 'Code'," &
" SUM(QUT1.[quantity]) AS 'Last360'" &
" INTO #Last360" &
" FROM QUT1 QUT1 INNER JOIN OITM OITM ON QUT1.[ItemCode] = OITM.[ItemCode] INNER JOIN OQUT OQUT ON QUT1.[DocEntry] = OQUT.[DocEntry]" &
" WHERE QUT1.[WhsCode] = OITM.[DfltWH] AND CONVERT(CHAR, QUT1.[DocDate], 112) < CONVERT(CHAR, GetDate()-270, 112) AND CONVERT(CHAR, QUT1.[DocDate], 112) >= CONVERT(CHAR, GetDate()-360, 112) AND OQUT.[Canceled] != 'Y'" &
" GROUP BY QUT1.[ItemCode]" &
" SELECT OITW.[WhsCode] AS 'Warehouse'," &
" OITW.[ItemCode] AS 'Item Code'," &
" OITM.[ItemName] AS 'Item Description'," &
" ISNULL(QuoteSum.[Open], 0) AS 'Sales Quote Qty'," &
" OITW.[IsCommited] AS 'Sales Order Qty'," &
" (ISNULL(QuoteSum.[Open], 0) + OITW.[IsCommited]) AS 'Demand'," &
" OITW.[OnHand] AS 'In Stock Qty', OITW.[OnOrder] AS 'Purchase Order Qty'," &
" (OITW.[OnHand] + OITW.[OnOrder]) AS 'Available'," &
" OITW.[OnHand] - OITW.[IsCommited] - ISNULL(QuoteSum.[Open], 0) + OITW.[OnOrder] AS 'To Manufacture/Buy'," &
" Last360.[Last360] as 'Last 271-360'" &
" FROM OITW OITW LEFT OUTER JOIN #QuoteSum QuoteSum ON OITW.[ItemCode] = QuoteSum.[Code] INNER JOIN OITM OITM ON OITW.[ItemCode] = OITM.[ItemCode] AND OITW.[WhsCode] = OITM.[DfltWH] LEFT OUTER JOIN #Last360 Last360 ON OITW.[ItemCode] = Last360.[Code]" &
" WHERE OITM.[DfltWH] >=@Whs_From AND OITM.[DfltWH] <= @Whs_To" &
" BEGIN DROP TABLE #QuoteSum END" &
" BEGIN DROP TABLE #Last360 END;", cn)
ad.Fill(ds, "OITM")
dv.Table = ds.Tables("OITM")
Me.DataGridView1.DataSource = dv
Catch ex As Exception
MsgBox(ErrorToString)
End Try
End Sub
以下是我收到的确切错误消息:
System.Data.SqlClient.SqlException:超时已过期。超时 在完成操作或服务器之前经过的时间段 没有回应。在 System.Data.SqlClient.SqlConnection.OnError(SqlException异常, Boolean breakConnection)at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)在System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject System.Data.SqlClient.SqlDataReader.ConsumeMetaData()中的stateObj) 在System.Data.SqlClient.SqlDataReader.get_MetaData()at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior,String resetOptionsString)at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(的CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async)at System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String 方法,DbAsyncResult结果)at System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String 方法)at System.Data.SqlClient.SqlCommand.ExecuteReader(的CommandBehavior 行为,String方法)at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(的CommandBehavior 行为) System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(的CommandBehavior 在System.Data.Common.DbDataAdapter.FillInternal(DataSet。)的行为) dataset,DataTable [] datatables,Int32 startRecord,Int32 maxRecords, 字符串srcTable,IDbCommand命令,CommandBehavior行为)at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand命令, CommandBehavior行为)at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet,String srcTable)在CR_Test.Form1.Form1_Load(对象发送者,EventArgs e) 在c:\ users \ leroif \ documents \ visual studio 2013 \ Projects \ CR Test \ CR Test \ Form1.vb:第46行
答案 0 :(得分:0)
在Try语句之前放置以下代码,然后它不会忽略
Dim cmd = cn.CreateCommand()
cmd.CommandTimeout = 0