Question subject: Timeout error while updating record in SQLServer in ASP.NET
Posted: Thu Nov 06, 2008 3:09 pm
Joined: Sun Oct 19, 2008 3:47 pm Posts: 281 Has thanked: 0 time Have thanks: 1 time
I have developed an ASP.NET application and the code listed below is on the Update button, to update a record into the SQLServer database.
The application works fine and I can retrieve the record and after the any field is modified, I click the 'Update' button to update the changes. However, I get the following error on the line "ExeQry.ExecuteNonQuery()". The error displayed is "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."
I am not able to figure out what is causing the error. I did find out that if I updated any record in any table in this database through "SQL Query Analyser" or "Enterprise Manager", then the below code works fine. The application then works fine for a while and then the same error is displayed again.
It seems like it is a connection issue with the database or the database is set to an inactive state and hence causes the error. And after an update is done on the database using "Query Analyser", the connection is restored and hence the application starts working again
Has anybody on this group come across this issue. Please give me some insight into what the problem is.
Code:
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click Dim strConn As String Dim Conn As New SqlConnection Dim strSQL As String Dim ExeQry As SqlCommand
Try strConn = ConfigurationSettings.AppSettings("connectionString") Conn = New SqlConnection(strConn)
Catch exc1 As Exception Response.Write(exc1.Message) Finally If Not (Conn Is Nothing) Then If Conn.State = System.Data.ConnectionState.Open Then Conn.Close() End If End Try End Sub
AnswerBot
Question subject: Re: Timeout error while updating record in SQLServer in ASP.NET
Posted: Thu Nov 06, 2008 3:10 pm
Joined: Sun Oct 19, 2008 3:53 pm Posts: 229 Has thanked: 0 time Have thanks: 0 time
Make sure that the database is actually attached, that SQL Server is running when you try to execute the code, and that "connectionString" actually has a string pointing to the database.