ethem
ethem

Reputation: 2908

ODBC - ExecuteNonQuery gives timeout - > where to increase this?

I add C# group too in this, because this is not VB problem but ExecuteNonQuery gives timeout. how to increase the time-out?

Exact errormessage: ERROR [HYT00] [Microsoft][ODBC SQL Server Driver]Timeout expired

we do have cms system and in that CMS I have created a IFRAME which calls this ASPX +VB code, which is in different physicall folder and it has managed Pipeline Classic.

When I run this in Old application it works fine. But I copied the pages to the news server and created new application pool/website Call OldASPPAGES I get ODBC timeout on 'ExecuteNonQuery()' function below.

Sometimes I works but 9 of the 10 cases I gettimeout. I checked the records and there are 247 records. But below you see there are 2 sql statements composed per Each loop. (update and insert)... 2 x 247 records = approx. 500 records.

But since the sql statement is concantenated so 1 call of ExecuteNonQuery, executue does do 500 SQL Statements....

I know this is GARBAGE, unacceptable.... But I inherited so for the moment I can't rewrite that.

To the point:

Below are the original statemenst: I have just added : conn.ConnectionTimeout = 240 As you can see I've added 240 seconds, but I still get timeouts after approx. 30 secs... so this is not the right place....

question: - Why does this statement work in old ASP environment (without problem) and not in this environement in an IFRAME....

Can someone advice?

thanks

 Private Function data30bis_save(ByVal data_30bis_list, ByVal user_id)
        lblMessage.Text = "data30bis_save"
        Dim conn As OdbcConnection, cmd As OdbcCommand, ra As Integer, sql As String, data_30bis As Attest30bis.Data30bisCobonet
        ' important: always purge the old situation before loading the new one !
        data30bis_cleanup(user_id)
        conn = New OdbcConnection("dsn=chris2;uid=xxx;pwd=ssddddd;")
        conn.ConnectionTimeout = 240
        conn.Open()
        sql = ""
        lblMessage.Text = "st"
        For Each data_30bis In data_30bis_list
            sql = sql & "update usr_codes set "
            If Len(data_30bis.analyseDate) > 0 Then
                sql = sql & "a30b_analysedate=convert(datetime,'" & data_30bis.analyseDate.ToString & "',103)"
            Else
                sql = sql & "a30b_analysedate=getdate()"
            End If
            sql = sql & ", a30b_errorcode=" & data_30bis.errorCode
            sql = sql & ", a30b_inputcompanyidvalid=" & Abs(CInt(data_30bis.inputCompanyIdValid))
            sql = sql & ", a30b_inputnossvalid=" & Abs(CInt(data_30bis.inputNossValid))
            sql = sql & ", a30b_noss=" & data_30bis.noss
            sql = sql & ", a30b_reservecontractorconcept=" & Abs(CInt(data_30bis.reserveContractorConcept))
            If Len(data_30bis.reserveContractorDate) > 0 Then
                sql = sql & ", a30b_reservecontractordate=convert(datetime,'" & data_30bis.reserveContractorDate.ToString & "',103)"
            Else
                sql = sql & ", a30b_reservecontractordate=getdate()"
            End If
            sql = sql & ", a30b_reservemakingconcept=" & Abs(CInt(data_30bis.reserveMakingConcept))
            If Len(data_30bis.reserveMakingDate) > 0 Then
                sql = sql & ", a30b_reservemakingdate=convert(datetime,'" & data_30bis.reserveMakingDate.ToString & "',103)"
            Else
                sql = sql & ", a30b_reservemakingdate=getdate()"
            End If
            sql = sql & ", a30b_date_modified=getdate()"
            sql = sql & " where user_id='" & user_id & "' and no_tva='" & data_30bis.companyId & "' and cd_pays_tva = 'BE'"
            sql = sql & vbCrLf
            ' 2nd SQL
            sql = sql & "insert a30b_controles (dt_ctrl, user_id, cd_pays_tva, no_tva, no_societe, a30b_analysedate, a30b_errorcode, a30b_inputcompanyidvalid, a30b_inputnossvalid, "
            sql = sql & "a30b_noss, a30b_reservecontractorconcept, a30b_reservecontractordate, a30b_reservemakingconcept, a30b_reservemakingdate, a30b_companyId) "
            sql = sql & "values (getdate(),'" & user_id & "','FR','massif',''," & "convert(datetime,'" & data_30bis.analyseDate.ToString & "',103)"
            sql = sql & "," & data_30bis.errorCode & "," & Abs(CInt(data_30bis.inputCompanyIdValid)) & "," & Abs(CInt(data_30bis.inputNossValid)) & "," & data_30bis.noss & "," & Abs(CInt(data_30bis.reserveContractorConcept))
            sql = sql & ",convert(datetime,'" & data_30bis.reserveContractorDate.ToString & "',103)," & Abs(CInt(data_30bis.reserveMakingConcept))
            sql = sql & ",convert(datetime,'" & data_30bis.reserveMakingDate.ToString & "',103)," & data_30bis.companyId & ")"
            sql = sql & vbCrLf
        Next
        lblMessage.Text = sql
        cmd = New OdbcCommand(sql, conn)
        ra = cmd.ExecuteNonQuery()
        lblMessage.Text = "ssssst"
        conn.Close()
        cmd = Nothing
        conn = Nothing
        lblMessage.Text = "ssssat"
        Return ra
    End Function

Upvotes: 3

Views: 8570

Answers (2)

Noorjahan
Noorjahan

Reputation: 21

lblMessage.Text = sql       
cmd = New OdbcCommand(sql, conn)  

cmd.CommandTimeout= 200   

ra = cmd.ExecuteNonQuery()      
lblMessage.Text = "ssssst" 

Upvotes: 2

Frederik Gheysels
Frederik Gheysels

Reputation: 56934

Have you tried the CommandTimeout property on the Command class yet ?

However, that's only symptom-fixing. Can't you tweak your query to make it more performant ?

Upvotes: 0

Related Questions