Solved

Opening a connection to oracle database using ado takes more time when network failure

Posted on 2004-10-29
317 Views
Last Modified: 2013-12-25
Hi,

I am using ado 2.8 version. I tried for opening a connection object in synchronous and asynchronous mode. In asynchronus  mode it takes 1.5 minutes for returning an error when network failure. For avoiding this I tried in asynchronous mode. Now the contol is coming to the next line, but when I tried to cancel it, it also taking that much time. In effect I can't see any change in time delay when there is no connectivity. I want to cancel/close the connection after 30 seconds and control should be in the very next line. How can I do it?

The code I used is given below

dim  gc_connection    as new adodb.connection
    gs_connect_data = "dsn=esme_linux;UID=cdr;pwd=cdr"
    gc_connection.Provider = "MSDASQL"
    gc_connection.ConnectionString = gs_connect_data
    gc_connection.ConnectionTimeout = 30
    c = Now
    gc_connection.Open , , , adAsyncConnect
    c = Now
    Do While True
        If DateDiff("s", c, Now) > 30 then
            If CBool(gc_connection.State And adStateConnecting) Then
               gc_connection.Cancel
'Comes here only after 1.5 minute if there is no connectivity
               MsgBox "open canceled." & c & "," & Now
               Exit Sub
            Else
               MsgBox "connection success." & c & "," & Now
               Exit Do
            End If
        ElseIf gc_connection.State <> 1 Then
            sleep(1)
        End If
    Loop
    gc_connection.Close
    Set gc_connection = Nothing

Seeja
0
Question by:Seejaanilkumar
    3 Comments
     
    LVL 44

    Expert Comment

    by:Arthur_Wood
    Are you not attempting to connect to an ORACLE database?

    This line:

     gc_connection.Provider = "MSDASQL"


    specifies that your provider is for SQL Server.

    Change it to:

     gc_connection.Provider = "MSDAORA"

    and then re-try.


    like this:

    dim  gc_connection    as new adodb.connection
        gs_connect_data = "dsn=esme_linux;UID=cdr;pwd=cdr"
        gc_connection.Provider = "MSDAORA"
        gc_connection.ConnectionString = gs_connect_data
        gc_connection.ConnectionTimeout = 30
        c = Now
        gc_connection.Open , , , adAsyncConnect
        c = Now
        Do While True
            If DateDiff("s", c, Now) > 30 then
                If CBool(gc_connection.State And adStateConnecting) Then
                   gc_connection.Cancel
    'Comes here only after 1.5 minute if there is no connectivity
                   MsgBox "open canceled." & c & "," & Now
                   Exit Sub
                Else
                   MsgBox "connection success." & c & "," & Now
                   Exit Do
                End If
            ElseIf gc_connection.State <> 1 Then
                sleep(1)
            End If
        Loop
        gc_connection.Close
        Set gc_connection = Nothing


    AW
    0
     

    Author Comment

    by:Seejaanilkumar
    My database can be oracle, sql server, access or any database which can be connected through a dsn. I am using this provider bcz all the databases can be connetced throgh this provider. If it is MSDAORA, only oracle database connectivity can be established. So my provider must be MSDASQL. The connection timeout is working in other databases such as SQL server etc. But with oracle, my exe will be seemed to be idle in that line (.cancel) in network failure.
    0
     

    Accepted Solution

    by:
    PAQed with points refunded (250)

    modulo
    Community Support Moderator
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    933 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now