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. Testing SQL Connection String - Runtime

Testing SQL Connection String - Runtime

Scheduled Pinned Locked Moved Visual Basic
helpsysadmindatabasesql-servertesting
3 Posts 2 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.
  • S Offline
    S Offline
    sa Eish
    wrote on last edited by
    #1

    I have a scenario where the program needs to have a variable connection string for the SQL server. The string is combined a collection of: • ServerName • SqlDatabase Name • User Name • Password • Connection Timeout Value Every time the connection string change it needs to validate the string and other operations needs to run. The problem comes in when the connection string has incorrect information. I have tried multi threads as I want the users to continue working on other functions while the system test the connection, but if the connection string generate an error it overpower all the threads and stall the system in any case… Is there a better why and faster why to test the connection, with out letting the user/system wait for response SQL connection timeout? PS: Reducing the timeout doesn’t help as the network has at certain times slow response times. This all happens in RunTime... **************************************************************************** I am not english so leave my grammer and spelling alone... :Mad: :Cool: ****************************************************************************

    K 1 Reply Last reply
    0
    • S sa Eish

      I have a scenario where the program needs to have a variable connection string for the SQL server. The string is combined a collection of: • ServerName • SqlDatabase Name • User Name • Password • Connection Timeout Value Every time the connection string change it needs to validate the string and other operations needs to run. The problem comes in when the connection string has incorrect information. I have tried multi threads as I want the users to continue working on other functions while the system test the connection, but if the connection string generate an error it overpower all the threads and stall the system in any case… Is there a better why and faster why to test the connection, with out letting the user/system wait for response SQL connection timeout? PS: Reducing the timeout doesn’t help as the network has at certain times slow response times. This all happens in RunTime... **************************************************************************** I am not english so leave my grammer and spelling alone... :Mad: :Cool: ****************************************************************************

      K Offline
      K Offline
      Kschuler
      wrote on last edited by
      #2

      I'm not sure if it is faster, but you could test the SQL connection by using a Try/Catch block to see if the connection can be opened before you actually use the connection. It would look something like this:

         Try
                  iconn.Open()
                  boolReturn = True
              Catch ex As OleDb.OleDbException
                  boolReturn = False
              Catch ex As SqlClient.SqlException
                  boolReturn = False
              Catch ex As Odbc.OdbcException 
                  boolReturn = False 
              Catch ex As Exception
                  boolReturn = False
              Finally
                  'Always close connection
                  If iconn.State = ConnectionState.Open Then
                      iconn.Close()
                  End If
              End Try
      

      Hope this helps.

      S 1 Reply Last reply
      0
      • K Kschuler

        I'm not sure if it is faster, but you could test the SQL connection by using a Try/Catch block to see if the connection can be opened before you actually use the connection. It would look something like this:

           Try
                    iconn.Open()
                    boolReturn = True
                Catch ex As OleDb.OleDbException
                    boolReturn = False
                Catch ex As SqlClient.SqlException
                    boolReturn = False
                Catch ex As Odbc.OdbcException 
                    boolReturn = False 
                Catch ex As Exception
                    boolReturn = False
                Finally
                    'Always close connection
                    If iconn.State = ConnectionState.Open Then
                        iconn.Close()
                    End If
                End Try
        

        Hope this helps.

        S Offline
        S Offline
        sa Eish
        wrote on last edited by
        #3

        I am testing the connection string by opening it and then closing the connection which has been assigned the function of testing. The problem comes in when u open the connection and the server is not there. It stalls the whole system for 30 seconds (Default Time out).

        Try
        	_conn.ConnectionString = ReconfigConnString() 
        

        I am looking for an idea where the system can test the connection AND do the other functions that needs to be complete before the form close. In multi threading the connection thread will over power the other threads and will cause one of two things. Deadlocks or either full system stalling until time out.:cool: System complete...bug free? I'll find a bug. :zzz:

        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