Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Timeout Expired The timeout period elapsed prior to completion

Timeout Expired The timeout period elapsed prior to completion

Scheduled Pinned Locked Moved Database
databasesql-serversysadminhelpannouncement
13 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jaffer Mumtaz
    wrote on last edited by
    #1

    The following function is used in my code to store PDF as BLOB in SQL Server database. When i am running my application, sometimes after the application is running for long time period and continusly updating database single field in SQL server containing millions of record it gives the following exception on cmdSQL.ExecuteNonQuery() Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. I have checked the query it does not take much time to execute againts SQL Server so please dont give me suggestion of setting timeout property of command object. I need to know why this error comes after long execution time and how can resolve it. Your immediate response will be higly appreciated. Protected Overrides Function PutPDFFile(ByVal strFileName As String) As Boolean Dim cmdSQL As SqlClient.SqlCommand Dim blnReturn As Boolean = False Dim objParam As SqlClient.SqlParameter Dim arrData() As Byte Try If Not IO.File.Exists(strFileName) Then Throw New Exception("PDF file not found:" & strFileName) Else arrData = ReadFile(strFileName) End If cmdSQL = New SqlClient.SqlCommand("UPDATE [] SET [File_Name] = @PDFName, [File] = @PDFData WHERE [File_Name] = @DATName".Replace("", Me.Job.JobName), Me.m_cnnSQL) cmdSQL.CommandType = CommandType.Text objParam = cmdSQL.Parameters.Add("@PDFName", SqlDbType.VarChar) objParam.Value = strFileName.Substring(strFileName.LastIndexOf(IO.Path.DirectorySeparatorChar) + 1) objParam = cmdSQL.Parameters.Add("@PDFData", SqlDbType.Image) objParam.Value = arrData objParam = cmdSQL.Parameters.Add("@DATName", SqlDbType.VarChar) objParam.Value = strFileName.Substring(strFileName.LastIndexOf(IO.Path.DirectorySeparatorChar) + 1).Replace("pdf", "dat") cmdSQL.ExecuteNonQuery() cmdSQL.Dispose() blnReturn = True Catch ex As Exception Me.m_objLog.Log(ex.Message, SOARLogType.sltLogOnly) Finally If IO.File.Exists(strFileName) Then IO.File.Delete(strFileName) cmdSQL = Nothing End Try Return blnReturn End Function

    O M A 4 Replies Last reply
    0
    • J Jaffer Mumtaz

      The following function is used in my code to store PDF as BLOB in SQL Server database. When i am running my application, sometimes after the application is running for long time period and continusly updating database single field in SQL server containing millions of record it gives the following exception on cmdSQL.ExecuteNonQuery() Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. I have checked the query it does not take much time to execute againts SQL Server so please dont give me suggestion of setting timeout property of command object. I need to know why this error comes after long execution time and how can resolve it. Your immediate response will be higly appreciated. Protected Overrides Function PutPDFFile(ByVal strFileName As String) As Boolean Dim cmdSQL As SqlClient.SqlCommand Dim blnReturn As Boolean = False Dim objParam As SqlClient.SqlParameter Dim arrData() As Byte Try If Not IO.File.Exists(strFileName) Then Throw New Exception("PDF file not found:" & strFileName) Else arrData = ReadFile(strFileName) End If cmdSQL = New SqlClient.SqlCommand("UPDATE [] SET [File_Name] = @PDFName, [File] = @PDFData WHERE [File_Name] = @DATName".Replace("", Me.Job.JobName), Me.m_cnnSQL) cmdSQL.CommandType = CommandType.Text objParam = cmdSQL.Parameters.Add("@PDFName", SqlDbType.VarChar) objParam.Value = strFileName.Substring(strFileName.LastIndexOf(IO.Path.DirectorySeparatorChar) + 1) objParam = cmdSQL.Parameters.Add("@PDFData", SqlDbType.Image) objParam.Value = arrData objParam = cmdSQL.Parameters.Add("@DATName", SqlDbType.VarChar) objParam.Value = strFileName.Substring(strFileName.LastIndexOf(IO.Path.DirectorySeparatorChar) + 1).Replace("pdf", "dat") cmdSQL.ExecuteNonQuery() cmdSQL.Dispose() blnReturn = True Catch ex As Exception Me.m_objLog.Log(ex.Message, SOARLogType.sltLogOnly) Finally If IO.File.Exists(strFileName) Then IO.File.Delete(strFileName) cmdSQL = Nothing End Try Return blnReturn End Function

      O Offline
      O Offline
      OMalleyW
      wrote on last edited by
      #2

      in your connection string try adding pooling=false will

      1 Reply Last reply
      0
      • J Jaffer Mumtaz

        The following function is used in my code to store PDF as BLOB in SQL Server database. When i am running my application, sometimes after the application is running for long time period and continusly updating database single field in SQL server containing millions of record it gives the following exception on cmdSQL.ExecuteNonQuery() Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. I have checked the query it does not take much time to execute againts SQL Server so please dont give me suggestion of setting timeout property of command object. I need to know why this error comes after long execution time and how can resolve it. Your immediate response will be higly appreciated. Protected Overrides Function PutPDFFile(ByVal strFileName As String) As Boolean Dim cmdSQL As SqlClient.SqlCommand Dim blnReturn As Boolean = False Dim objParam As SqlClient.SqlParameter Dim arrData() As Byte Try If Not IO.File.Exists(strFileName) Then Throw New Exception("PDF file not found:" & strFileName) Else arrData = ReadFile(strFileName) End If cmdSQL = New SqlClient.SqlCommand("UPDATE [] SET [File_Name] = @PDFName, [File] = @PDFData WHERE [File_Name] = @DATName".Replace("", Me.Job.JobName), Me.m_cnnSQL) cmdSQL.CommandType = CommandType.Text objParam = cmdSQL.Parameters.Add("@PDFName", SqlDbType.VarChar) objParam.Value = strFileName.Substring(strFileName.LastIndexOf(IO.Path.DirectorySeparatorChar) + 1) objParam = cmdSQL.Parameters.Add("@PDFData", SqlDbType.Image) objParam.Value = arrData objParam = cmdSQL.Parameters.Add("@DATName", SqlDbType.VarChar) objParam.Value = strFileName.Substring(strFileName.LastIndexOf(IO.Path.DirectorySeparatorChar) + 1).Replace("pdf", "dat") cmdSQL.ExecuteNonQuery() cmdSQL.Dispose() blnReturn = True Catch ex As Exception Me.m_objLog.Log(ex.Message, SOARLogType.sltLogOnly) Finally If IO.File.Exists(strFileName) Then IO.File.Delete(strFileName) cmdSQL = Nothing End Try Return blnReturn End Function

        M Offline
        M Offline
        miah alom
        wrote on last edited by
        #3

        cmdSQL.CommandTimeout = 30 is by default. Try setting it to 60.

        1 Reply Last reply
        0
        • J Jaffer Mumtaz

          The following function is used in my code to store PDF as BLOB in SQL Server database. When i am running my application, sometimes after the application is running for long time period and continusly updating database single field in SQL server containing millions of record it gives the following exception on cmdSQL.ExecuteNonQuery() Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. I have checked the query it does not take much time to execute againts SQL Server so please dont give me suggestion of setting timeout property of command object. I need to know why this error comes after long execution time and how can resolve it. Your immediate response will be higly appreciated. Protected Overrides Function PutPDFFile(ByVal strFileName As String) As Boolean Dim cmdSQL As SqlClient.SqlCommand Dim blnReturn As Boolean = False Dim objParam As SqlClient.SqlParameter Dim arrData() As Byte Try If Not IO.File.Exists(strFileName) Then Throw New Exception("PDF file not found:" & strFileName) Else arrData = ReadFile(strFileName) End If cmdSQL = New SqlClient.SqlCommand("UPDATE [] SET [File_Name] = @PDFName, [File] = @PDFData WHERE [File_Name] = @DATName".Replace("", Me.Job.JobName), Me.m_cnnSQL) cmdSQL.CommandType = CommandType.Text objParam = cmdSQL.Parameters.Add("@PDFName", SqlDbType.VarChar) objParam.Value = strFileName.Substring(strFileName.LastIndexOf(IO.Path.DirectorySeparatorChar) + 1) objParam = cmdSQL.Parameters.Add("@PDFData", SqlDbType.Image) objParam.Value = arrData objParam = cmdSQL.Parameters.Add("@DATName", SqlDbType.VarChar) objParam.Value = strFileName.Substring(strFileName.LastIndexOf(IO.Path.DirectorySeparatorChar) + 1).Replace("pdf", "dat") cmdSQL.ExecuteNonQuery() cmdSQL.Dispose() blnReturn = True Catch ex As Exception Me.m_objLog.Log(ex.Message, SOARLogType.sltLogOnly) Finally If IO.File.Exists(strFileName) Then IO.File.Delete(strFileName) cmdSQL = Nothing End Try Return blnReturn End Function

          A Offline
          A Offline
          Andy Brummer
          wrote on last edited by
          #4

          First load up your query in query analyzer and check the execution plan to make sure it is not doing a table scan. If it is check to see if there is an index on [File_Name], if not then add one. If there is then try rebuilding the statistics on that table. Increasing the timeout value should be the approach of last resort.

          M 1 Reply Last reply
          0
          • A Andy Brummer

            First load up your query in query analyzer and check the execution plan to make sure it is not doing a table scan. If it is check to see if there is an index on [File_Name], if not then add one. If there is then try rebuilding the statistics on that table. Increasing the timeout value should be the approach of last resort.

            M Offline
            M Offline
            miah alom
            wrote on last edited by
            #5

            Agreed. But this is just not the execution plan and table statistics but sometimes the network traffic is high and the default CommandTimeout is just not sufficient. I have encountered this before.

            A 1 Reply Last reply
            0
            • J Jaffer Mumtaz

              The following function is used in my code to store PDF as BLOB in SQL Server database. When i am running my application, sometimes after the application is running for long time period and continusly updating database single field in SQL server containing millions of record it gives the following exception on cmdSQL.ExecuteNonQuery() Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. I have checked the query it does not take much time to execute againts SQL Server so please dont give me suggestion of setting timeout property of command object. I need to know why this error comes after long execution time and how can resolve it. Your immediate response will be higly appreciated. Protected Overrides Function PutPDFFile(ByVal strFileName As String) As Boolean Dim cmdSQL As SqlClient.SqlCommand Dim blnReturn As Boolean = False Dim objParam As SqlClient.SqlParameter Dim arrData() As Byte Try If Not IO.File.Exists(strFileName) Then Throw New Exception("PDF file not found:" & strFileName) Else arrData = ReadFile(strFileName) End If cmdSQL = New SqlClient.SqlCommand("UPDATE [] SET [File_Name] = @PDFName, [File] = @PDFData WHERE [File_Name] = @DATName".Replace("", Me.Job.JobName), Me.m_cnnSQL) cmdSQL.CommandType = CommandType.Text objParam = cmdSQL.Parameters.Add("@PDFName", SqlDbType.VarChar) objParam.Value = strFileName.Substring(strFileName.LastIndexOf(IO.Path.DirectorySeparatorChar) + 1) objParam = cmdSQL.Parameters.Add("@PDFData", SqlDbType.Image) objParam.Value = arrData objParam = cmdSQL.Parameters.Add("@DATName", SqlDbType.VarChar) objParam.Value = strFileName.Substring(strFileName.LastIndexOf(IO.Path.DirectorySeparatorChar) + 1).Replace("pdf", "dat") cmdSQL.ExecuteNonQuery() cmdSQL.Dispose() blnReturn = True Catch ex As Exception Me.m_objLog.Log(ex.Message, SOARLogType.sltLogOnly) Finally If IO.File.Exists(strFileName) Then IO.File.Delete(strFileName) cmdSQL = Nothing End Try Return blnReturn End Function

              O Offline
              O Offline
              OMalleyW
              wrote on last edited by
              #6

              by default the SqlConnection object sets pooling = true which means there is a limited ammount of time that connection is allowed in the pool. Clicky[^] I have ran into the same situation where no matter how good my execution plan was or how normalized my data was I would still get time outs. After adding pooling = false to my connection strings the time outs stopped.. hope this helps Will

              M 1 Reply Last reply
              0
              • O OMalleyW

                by default the SqlConnection object sets pooling = true which means there is a limited ammount of time that connection is allowed in the pool. Clicky[^] I have ran into the same situation where no matter how good my execution plan was or how normalized my data was I would still get time outs. After adding pooling = false to my connection strings the time outs stopped.. hope this helps Will

                M Offline
                M Offline
                miah alom
                wrote on last edited by
                #7

                This is true, but there are two aspects of it, command timeout and connection timeout. Do you think they are related?

                O 1 Reply Last reply
                0
                • M miah alom

                  This is true, but there are two aspects of it, command timeout and connection timeout. Do you think they are related?

                  O Offline
                  O Offline
                  OMalleyW
                  wrote on last edited by
                  #8

                  I think it is a mix of several settings. You could set your command timeout to 4 hours if you wanted to but if the connection is pooling then you are stuck. Clicky[^] Question 4: The ConnectionTimeout property cannot be reset on a pooled connection I may be wrong but this worked for me... Will

                  M 1 Reply Last reply
                  0
                  • O OMalleyW

                    I think it is a mix of several settings. You could set your command timeout to 4 hours if you wanted to but if the connection is pooling then you are stuck. Clicky[^] Question 4: The ConnectionTimeout property cannot be reset on a pooled connection I may be wrong but this worked for me... Will

                    M Offline
                    M Offline
                    miah alom
                    wrote on last edited by
                    #9

                    Thanks for the link.

                    J 1 Reply Last reply
                    0
                    • M miah alom

                      Agreed. But this is just not the execution plan and table statistics but sometimes the network traffic is high and the default CommandTimeout is just not sufficient. I have encountered this before.

                      A Offline
                      A Offline
                      Andy Brummer
                      wrote on last edited by
                      #10

                      It depends how high the timeout is and how much traffic you need to support. If you set your timeout too high, the entire site can be brought down by a few poorly performing pages. The timeout exists for a very important reason, to allow the server to recover when it is overloaded. I have encountered this a few times myself. IMHO. Exceution plan and table statistics are the most common reasons for an update to run slow especially when there are a number of records in the table and should be the first solutions considered since they have very little cost. Next, I'd evaluate contention with other queries by loading up the profiler and looking for long running operations.


                      I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

                      1 Reply Last reply
                      0
                      • M miah alom

                        Thanks for the link.

                        J Offline
                        J Offline
                        Jaffer Mumtaz
                        wrote on last edited by
                        #11

                        Thanks guys for ur immediate response but i have tried the things u have pointed out. I ran the query through query analyzer and it seems to give me timeout their as well. I think this seems to be an issue with SQL server not with connection. My database only have 120000 records but i am storing PDF its size is over 10 GB. When i ran select query on a particular table it runs fine but when i try to update a row or record or delete a record it gives timeout using query analyzer. Any one who can point out this issue why is this happening. Once again thnx for ur immediate response. Jaffer

                        O A 2 Replies Last reply
                        0
                        • J Jaffer Mumtaz

                          Thanks guys for ur immediate response but i have tried the things u have pointed out. I ran the query through query analyzer and it seems to give me timeout their as well. I think this seems to be an issue with SQL server not with connection. My database only have 120000 records but i am storing PDF its size is over 10 GB. When i ran select query on a particular table it runs fine but when i try to update a row or record or delete a record it gives timeout using query analyzer. Any one who can point out this issue why is this happening. Once again thnx for ur immediate response. Jaffer

                          O Offline
                          O Offline
                          OMalleyW
                          wrote on last edited by
                          #12

                          Then this is totally a data problem. You could try to partition your table... Here is some light reading on the how and why. Clcky[^] hope this helps Will -- modified at 12:33 Monday 12th September, 2005

                          1 Reply Last reply
                          0
                          • J Jaffer Mumtaz

                            Thanks guys for ur immediate response but i have tried the things u have pointed out. I ran the query through query analyzer and it seems to give me timeout their as well. I think this seems to be an issue with SQL server not with connection. My database only have 120000 records but i am storing PDF its size is over 10 GB. When i ran select query on a particular table it runs fine but when i try to update a row or record or delete a record it gives timeout using query analyzer. Any one who can point out this issue why is this happening. Once again thnx for ur immediate response. Jaffer

                            A Offline
                            A Offline
                            Andy Brummer
                            wrote on last edited by
                            #13

                            First of all the image data type can only hold 2GB of data so even if your operation didn't time out, it would fail. If you have to store documents which are that large, you are going to have to increase your command timeout. The connection timeout should only increase if the server is getting overloaded. 120,000 records is a relatively small amount for sql server to handle if indexes are setup properly. Make sure the indexes are on the table to support all your queries. If that doesn't fix the problem, then start looking to see if SQL server is bound up with disk or memory access from the large files, or if it is just load from the tables in the database.


                            I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups