Seejaanilkumar
asked on
Opening a connection to oracle database using ado takes more time when network failure
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;pw d=cdr"
gc_connection.Provider = "MSDASQL"
gc_connection.ConnectionSt ring = gs_connect_data
gc_connection.ConnectionTi meout = 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
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;pw
gc_connection.Provider = "MSDASQL"
gc_connection.ConnectionSt
gc_connection.ConnectionTi
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
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;pw
gc_connection.Provider = "MSDAORA"
gc_connection.ConnectionSt
gc_connection.ConnectionTi
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