Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

How to optimize VB.NET Code

Avatar of yaney00074
yaney00074 asked on
Visual Basic.NET
5 Comments1 Solution762 ViewsLast Modified:
Experts,

I need help in optimizing this code such a way it won't timeout while the job is running.
Error: Application Timeout exception

Here's the code
    Private Sub MainMethod()
        Dim objConn As SqlConnection = New SqlConnection(connString)
        '******* Initial sql to pull data from your table and into the tblTemp DataTable.
        '******* This should be the pKey and the HTML column in question
        Dim strSQL = "select FirstName, emailAddress from testExample"
        Dim objCmd As New SqlCommand(strSQL, objConn)
        objCmd.CommandType = CommandType.Text

        Try
            objConn.Open()

            Dim objDT As DataTable '(dt)
            '//execute the command and save the results in a datatable
            Dim objReader As SqlDataReader = objCmd.ExecuteReader()
            objDT = New DataTable("testTable")
            objDT.Load(objReader)

            Dim strUpdateSQL As String = ""
            Dim intCounter As Integer = 1

            For Each dDataRow As DataRow In objDT.Rows

                '//write what the data is when initially coming from the DB table
                Console.WriteLine("{0}....{1}", dDataRow("FirstName").ToString(), dDataRow("emailAddress").ToString())

                '// ******* Update SQL...in the WHERE statement use the PKey of the table
                strUpdateSQL = "UPDATE testExample SET FirstName = '" & removeHTMLTags(dDataRow("FirstName").ToString()) & "'"
                strUpdateSQL &= " WHERE emailAddress = '" & dDataRow("emailAddress").ToString() & "'"


                Try
                    Console.WriteLine("\tBegin Update On Row {0}...", intCounter.ToString())

                    Dim objConn2 As New SqlConnection(connString)

                    objConn2.Open()
                    Dim objCmd2 As New SqlCommand(strUpdateSQL, objConn2)
                    objCmd2.CommandType = CommandType.Text
                    objCmd2.ExecuteNonQuery()
                    objConn2.Close()

                    Console.WriteLine("")

                    intCounter = intCounter + 1

                Catch ex As SqlException
                    Console.WriteLine("Exception At Update... " + ex.Message.ToString())

                End Try
            Next

            '//Close the reader
            objReader.Close()
        Catch ex As SqlException
            Console.WriteLine(ex.Message.ToString())
        End Try
    End Sub



Thanks

ASKER CERTIFIED SOLUTION
Avatar of Joe_Griffith
Joe_Griffith

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answers