哪里放置OLE DB字符串CommandTimeout

时间:2018-10-21 21:20:28

标签: oledbconnection oledbcommand

我有一个Visual Studio程序,该程序更新SQL表“ Lab_Table”,然后该程序查找重复的数据。如果在5天之内存在任何重复项,则除了第一条记录外,所有重复项都将被删除。当有数据要检查是否有重复项时,将引发错误,指出查询超时失败。 sConnString的CommandTimeout =90。但是查询在30秒后仍显示错误。我认为但不确定,CommandTimeOut = 90必须位于sSQL =“ Delete ......”的代码下方,但不确定应将其放置在何处或如何放置。所有代码都在下面。非常感谢前进。

    'Connection string for database
    sConnString = "Provider=SQLOLEDB;Server=RICKNDELLM2800\SQLEXPRESS;Database=ExactMAXSAM;User ID=sa;Password=password;CommandTimeout=90;"

' This is the Last Query to Delete Duplicates and fails after 30 seconds
        sSQL = "DELETE From Lab_Table Where (((TDate > DateAdd(Day, -5, GETDATE()) And ((Auto) Not In (Select Min(Auto) As MinID FROM Lab_Table WHERE (TDate > DATEADD(day, -10, GETDATE()))GROUP BY LotNumber))))  And (Qty)=Qty)"

        With objCommand
            .Connection = oOleDbConnection
            .CommandText = sSQL
            .CommandType = CommandType.Text
            .ExecuteNonQuery()
        End With
        'oOleDbConnection.Close() ' data is completed and time to close the ole connection
        'oOleDbConnection = Nothing
    Catch ex As Exception '  this Catch is required but the ex As Exception and MessageBox.Show(ex.ToString) below are only for error messages   
        MessageBox.Show(ex.ToString)
    End Try
    frmgathertickets.Close() 'to close delete subform
End Sub

0 个答案:

没有答案