gpt4 book ai didi

sql - 超时已过期(cmd.CommandTimeout = 0 被忽略)

转载 作者:行者123 更新时间:2023-12-04 00:22:33 26 4
gpt4 key购买 nike

即使在设置 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: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() at 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 method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) at CR_Test.Form1.Form1_Load(Object sender, EventArgs e) in c:\users\leroif\documents\visual studio 2013\Projects\CR Test\CR Test\Form1.vb:line 46

最佳答案

问题是您覆盖了错误对象的超时值。

cmd.CommandTimeout = 0

但是您实际上并没有在之后的任何地方使用 cmd 对象。看起来您根本不需要创建命令对象。您的查询是使用 ad SqlDataAdapter 实例执行的,而不是 cmd 实例。

您需要做的是覆盖 SqlDataAdapter 的超时值。

我自己从未尝试过,但显然,这是如何完成的:

ad.SelectCommand.CommandTimeout=0

试一试。

关于sql - 超时已过期(cmd.CommandTimeout = 0 被忽略),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31430902/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com