Results 1 to 5 of 5

Thread: [RESOLVED] Server Connection

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    688

    Resolved [RESOLVED] Server Connection

    hi

    I have written the below code in MDI form . If network is dowm then sytem hangs for 15 seconds when the below code is trying to check connection to server . Is it possible that system should not be in hang like situation

    Private Sub Timer3_Timer()

    If cnn2.State Then cnn2.Close
    cnn2.Open "Driver=SQL Server;Server=" & Svr & ";Database=" & "Test" & ";uid=" & uid & ";pwd=" & pwd & ";"


    Thanks

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Server Connection

    Why would you write code like that? The timer ticks, connection is open, code closes the connection and opens it again, that is not a very good idea at all.

    Also why do you keep creating new threads on basically the same question. Seems like this makes at least 3 or 4 threads I have saw from you related to opening this connection.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    688

    Re: Server Connection

    Hi Datamiser

    can you help me with code what it should be

    Thanks

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Server Connection

    Well I don't know what you are trying to do really, even after 5 threads the only thing I have gathered is that you are trying to determine if the connection succeeds or not which you had some code for already in one of the other threads.

    You should not be closing the connection and then opening it like that. Normally you would open a connection, use it, close it. If you need to hold the connection open then you would check to see if it is already open and if it use then use it if not then open it.

  5. #5
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Re: Server Connection

    Why don't use timeout Property of Cnn2.
    Code:
    Private Sub Timer3_Timer()
    
    If cnn2.State Then cnn2.Close
    cnn2.ConnectionTimeout = 0
    cnn2.Open "Driver=SQL Server;Server=" & Svr & ";Database=" & "Test" & ";uid=" & uid & ";pwd=" & pwd & ";"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width