0

我一直在尝试执行存储过程,但每次单击从我的应用程序执行它时,它都会超时并出现以下错误:

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

如果需要对下面的例程进行任何更改,有什么想法吗?

Private Sub Reset()
    Dim connectionString As String = ConfigurationManager.ConnectionStrings("constring").ConnectionString
    Dim storedProcName As String = "insertnewSP"
    Dim conn As SqlConnection = New SqlConnection(connectionString)
    conn.Open()
    Dim command As SqlCommand = New SqlCommand(storedProcName, conn)
    command.CommandType = CommandType.StoredProcedure
    command.ExecuteNonQuery()
    command.Dispose()
    conn.Close()
    conn.Dispose()
End Sub
Protected Sub Refresh_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Refresh.Click
    ' Clean up text to return the Gridview to it's default state
    Reset()
    strsearch.Text = ""
    SearchString = ""
    gridView1.DataBind()
End Sub

非常感谢

4

1 回答 1

0

您的 CommandTimeout 可能在调用完成之前到期,试试这个:

Private Sub Reset()
    Dim connectionString As String = ConfigurationManager.ConnectionStrings("constring").ConnectionString
    Dim storedProcName As String = "insertnewSP"
    Dim conn As SqlConnection = New SqlConnection(connectionString)
    conn.Open()
    Dim command As SqlCommand = New SqlCommand(storedProcName, conn)
    command.CommandType = CommandType.StoredProcedure
    command.CommandTimeout = 180
    command.ExecuteNonQuery()
    command.Dispose()
    conn.Close()
    conn.Dispose()
End Sub

Protected Sub Refresh_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Refresh.Click
    ' Clean up text to return the Gridview to it's default state
    Reset()
    strsearch.Text = ""
    SearchString = ""
    gridView1.DataBind()
End Sub
于 2012-08-22T15:46:48.870 回答