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. General Programming
  3. Visual Basic
  4. Problem in VB while trying to execute SQL Code

Problem in VB while trying to execute SQL Code

Scheduled Pinned Locked Moved Visual Basic
helpdatabasexml
10 Posts 5 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.
  • N Offline
    N Offline
    nhsal69
    wrote on last edited by
    #1

    Hi there, wonder if you can help... I have a piece of VB code which uploads 2 large XMLs to SQL and then more code which allows the manipulation of the data to provide various bits of info which is then presented to Excel.. I was initially uploading each test XML file which were about 40K lines which made 16K Rows in each SQL table. I could then compare the two tables. The implementation requires XMLs of around 660K lines which, after uploading, become 144763 and 146741 rows in each table in SQL. My problem is that the statement I was using to compare these two tables, which worked with test data fails (no error is given) here is the code: SQLStr = "Select * into Temp_Delete_Oldest from " & First & " Select * into Temp_Delete_Newest from " & Second & " DELETE Temp_Delete_Oldest FROM Temp_Delete_Oldest INNER JOIN Temp_Delete_Newest ON Temp_Delete_Newest.Fullpath = Temp_Delete_Oldest.Fullpath" This works in SQL when it is entered as a New Query but fails when implemnted from the VB code. So, does anybody know why this fails and what I can do to stop it failing, bearing in mind it works with smaller SQL tables.... Cheers nhsal69

    E T 2 Replies Last reply
    0
    • N nhsal69

      Hi there, wonder if you can help... I have a piece of VB code which uploads 2 large XMLs to SQL and then more code which allows the manipulation of the data to provide various bits of info which is then presented to Excel.. I was initially uploading each test XML file which were about 40K lines which made 16K Rows in each SQL table. I could then compare the two tables. The implementation requires XMLs of around 660K lines which, after uploading, become 144763 and 146741 rows in each table in SQL. My problem is that the statement I was using to compare these two tables, which worked with test data fails (no error is given) here is the code: SQLStr = "Select * into Temp_Delete_Oldest from " & First & " Select * into Temp_Delete_Newest from " & Second & " DELETE Temp_Delete_Oldest FROM Temp_Delete_Oldest INNER JOIN Temp_Delete_Newest ON Temp_Delete_Newest.Fullpath = Temp_Delete_Oldest.Fullpath" This works in SQL when it is entered as a New Query but fails when implemnted from the VB code. So, does anybody know why this fails and what I can do to stop it failing, bearing in mind it works with smaller SQL tables.... Cheers nhsal69

      E Offline
      E Offline
      Eduard Keilholz
      wrote on last edited by
      #2

      Why don't you catch the exception and read what it tells you... That may help?

      .: I love it when a plan comes together :. http://www.zonderpunt.nl

      N 1 Reply Last reply
      0
      • E Eduard Keilholz

        Why don't you catch the exception and read what it tells you... That may help?

        .: I love it when a plan comes together :. http://www.zonderpunt.nl

        N Offline
        N Offline
        nhsal69
        wrote on last edited by
        #3

        The error generated is: A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Which is not really of any help, as this is the standard error when anything goes wrong when working with SQL from VB....

        L 1 Reply Last reply
        0
        • N nhsal69

          The error generated is: A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Which is not really of any help, as this is the standard error when anything goes wrong when working with SQL from VB....

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Did you use Exception.ToString() which shows ALL the available information, or just Exception.Message which only gives one line of text? :mad:

          Luc Pattyn [Forum Guidelines] [My Articles]


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


          1 Reply Last reply
          0
          • N nhsal69

            Hi there, wonder if you can help... I have a piece of VB code which uploads 2 large XMLs to SQL and then more code which allows the manipulation of the data to provide various bits of info which is then presented to Excel.. I was initially uploading each test XML file which were about 40K lines which made 16K Rows in each SQL table. I could then compare the two tables. The implementation requires XMLs of around 660K lines which, after uploading, become 144763 and 146741 rows in each table in SQL. My problem is that the statement I was using to compare these two tables, which worked with test data fails (no error is given) here is the code: SQLStr = "Select * into Temp_Delete_Oldest from " & First & " Select * into Temp_Delete_Newest from " & Second & " DELETE Temp_Delete_Oldest FROM Temp_Delete_Oldest INNER JOIN Temp_Delete_Newest ON Temp_Delete_Newest.Fullpath = Temp_Delete_Oldest.Fullpath" This works in SQL when it is entered as a New Query but fails when implemnted from the VB code. So, does anybody know why this fails and what I can do to stop it failing, bearing in mind it works with smaller SQL tables.... Cheers nhsal69

            T Offline
            T Offline
            The Man from U N C L E
            wrote on last edited by
            #5

            Check what the SQLStr evaluates to and try running that in SQL. This is building dynamically so if there was a type in the First or second variables then it will crash.

            If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) www.JacksonSoft.co.uk

            N 1 Reply Last reply
            0
            • T The Man from U N C L E

              Check what the SQLStr evaluates to and try running that in SQL. This is building dynamically so if there was a type in the First or second variables then it will crash.

              If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) www.JacksonSoft.co.uk

              N Offline
              N Offline
              nhsal69
              wrote on last edited by
              #6

              the full error is: "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding." This only occurs when the input files are the "large" ones, they also use the same variables "first and "second" as the small ones which complete successfully. After a bit of further investigation it appears as it is only when the VB send the calculation query to SQL that the error occurs (it creates the tables, which is the previous step)... I am attempting to increase the timeout period from default of 15 sec to more but this doesn't appear to resolve the problem... Any thoughts??? ***edit*** when stepping though the code and executing the "SQLCmd.ExecuteNonQuery()" it takes a count of approx 30 before the timeout error occurs, no matter what the "Connection Timeout=***;" in the connection string is set to...

              A T 2 Replies Last reply
              0
              • N nhsal69

                the full error is: "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding." This only occurs when the input files are the "large" ones, they also use the same variables "first and "second" as the small ones which complete successfully. After a bit of further investigation it appears as it is only when the VB send the calculation query to SQL that the error occurs (it creates the tables, which is the previous step)... I am attempting to increase the timeout period from default of 15 sec to more but this doesn't appear to resolve the problem... Any thoughts??? ***edit*** when stepping though the code and executing the "SQLCmd.ExecuteNonQuery()" it takes a count of approx 30 before the timeout error occurs, no matter what the "Connection Timeout=***;" in the connection string is set to...

                A Offline
                A Offline
                Ashfield
                wrote on last edited by
                #7

                Just goes to show the importance of checking the error message fully, doesn't it? You need to set both the connection and query timeouts I suspect.

                Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

                N 1 Reply Last reply
                0
                • N nhsal69

                  the full error is: "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding." This only occurs when the input files are the "large" ones, they also use the same variables "first and "second" as the small ones which complete successfully. After a bit of further investigation it appears as it is only when the VB send the calculation query to SQL that the error occurs (it creates the tables, which is the previous step)... I am attempting to increase the timeout period from default of 15 sec to more but this doesn't appear to resolve the problem... Any thoughts??? ***edit*** when stepping though the code and executing the "SQLCmd.ExecuteNonQuery()" it takes a count of approx 30 before the timeout error occurs, no matter what the "Connection Timeout=***;" in the connection string is set to...

                  T Offline
                  T Offline
                  The Man from U N C L E
                  wrote on last edited by
                  #8

                  A couple of possibilities worth checking. In Object Explorer right click on the SQL Server 2005 instance select Properties. On the Connections tab check the value of Remote_query timeout. On the Advanced tab check the value of Remote Login Timeout. Either of these would take precedence over your connection string settings.

                  If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) www.JacksonSoft.co.uk

                  1 Reply Last reply
                  0
                  • A Ashfield

                    Just goes to show the importance of checking the error message fully, doesn't it? You need to set both the connection and query timeouts I suspect.

                    Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

                    N Offline
                    N Offline
                    nhsal69
                    wrote on last edited by
                    #9

                    Problem resolved, here is the code for the SQL connection: Dim mycon As New SqlConnection(conString) Dim SQLConn As New SqlConnection() 'The SQL Connection Dim SQLCmd As New SqlCommand() 'The SQL Command SQLConn.ConnectionString = myconnection 'Set the Connection String SQLConn.Open() 'Open the connection SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command SQLCmd.CommandText = SQLStr 'Sets the SQL String **SQLCmd.CommandTimeout = 60** SQLCmd.ExecuteNonQuery() 'Executes SQL Commands Non-Querys only SQLConn.Close() 'Close the connection mycon.Close() Console.WriteLine("Connection Closed") The Bolded lin ei the new one which resolves my issue.. Thanks

                    A 1 Reply Last reply
                    0
                    • N nhsal69

                      Problem resolved, here is the code for the SQL connection: Dim mycon As New SqlConnection(conString) Dim SQLConn As New SqlConnection() 'The SQL Connection Dim SQLCmd As New SqlCommand() 'The SQL Command SQLConn.ConnectionString = myconnection 'Set the Connection String SQLConn.Open() 'Open the connection SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command SQLCmd.CommandText = SQLStr 'Sets the SQL String **SQLCmd.CommandTimeout = 60** SQLCmd.ExecuteNonQuery() 'Executes SQL Commands Non-Querys only SQLConn.Close() 'Close the connection mycon.Close() Console.WriteLine("Connection Closed") The Bolded lin ei the new one which resolves my issue.. Thanks

                      A Offline
                      A Offline
                      Ashfield
                      wrote on last edited by
                      #10

                      Good :)

                      Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

                      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