none
odbc.odbcConnection.ConnectionTimeout Vs System.data.Common.dbConnection.ConnectionTimeout RRS feed

  • Question

  • Hi.

    I am working on a VB application using the .net framework 4.5.2 and i encounter an issue with the property odbc.odbcConnection.ConnectionTimeout.

    I set this property to 1, but when i can't connect to the database due to a netword connection problem, the timeout is not 1 but 15. it seems my odbcconnection used its parent property (System.data.Common.dbConnection.ConnectionTimeout) instead of its own property i set before opening the connection.

                dbConRef = New Odbc.OdbcConnection
                dbConRef.ConnectionString = cnxString
                dbConRef.ConnectionTimeout = 1
                dbConRef.Open()

    if someone encountered this issue, or have a solution to this problem...

    Thanks a lot.

    Mad.

    Monday, January 4, 2016 9:16 AM

Answers

  • Hi.

     i found the problem. It seems the odbc connection timeout doesn't manage the network connection timeout in case of the database is on an other server.

      To solve my problem, before connecting to the database, i try a socket connection to the server with the database communication port.

    ' Network check
                If sHost <> "" Then
                    Dim ipHostInfo As IPHostEntry = Dns.GetHostEntry(sHost)
                    Dim ipAddress As IPAddress = ipHostInfo.AddressList(0)
                    Dim remoteEP As New IPEndPoint(ipAddress, sPort)

                    ' Create a TCP/IP socket.
                    Dim sender As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                    Dim result As IAsyncResult
                    ' Connect the socket to the remote endpoint.
                    Try
                        result = sender.BeginConnect(remoteEP, Nothing, Nothing)
                        bRetour = result.AsyncWaitHandle.WaitOne(1250)
                        If Not bRetour Then
                            Return False
                        End If
                    Catch ex As Exception
                        Return False
                    Finally
                        sender.Close()
                    End Try

                End If

                ' Database connection
                dbConRef = New Odbc.OdbcConnection
                dbConRef.ConnectionString = cnxString
                dbConRef.ConnectionTimeout = dbTimeout
                dbConRef.OpenAsync()

      Thanks all for your investigations.

      Best regards.

      Mad.

    • Marked as answer by Madtotor Thursday, January 21, 2016 10:00 AM
    Thursday, January 21, 2016 10:00 AM

All replies

  • Hi Mad,

    Since you mentioned your case related to odbc.odbcConnection. It belongs to Ado.Net, I will move your case to Ado datadet forum for better support.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Tuesday, January 5, 2016 1:25 AM
    Tuesday, January 5, 2016 1:24 AM
  • Hi Madtotor,

    According to your description,  I made a vb application demo by using .netFramework4.5.2, and used odbc connection localdb on my machine, then connection time worked when I manually change its value. you could set connectiontimeout value on your connectionstring, and check if it works. If it doesn't work, could you please share your project to me for a better solution.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, January 5, 2016 10:01 AM
    Moderator
  • Give timeout to your command command.commandTimeout instead of dbConRef.ConnectionTimeout = 1.

    Tuesday, January 5, 2016 10:08 AM
  • Hi All.

      Thanks for your investigations.

    @Fred : In the spy browse, if I take a look on the object dbConRef, i can see the property connectionTimeout set to 1, but i also see the property System.data.Common.dbConnection.ConnectionTimeout set to 15.  When the database is not reachable, the open command lasts 15 seconds. i verified it with the debugger mode.

                 From the MS documentation (https://msdn.microsoft.com/en-us/library/system.data.odbc.odbcconnection.connectiontimeout%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396), it seems we can't set this property in the connectionString. 

    @Maruthi : i did it too, but i have this timeout problem during the open command (and only when the database is not reachable).

     For more informations, my project is basic :). Each user of the applicaton use a local database (because they can work without any connection to their company network). To be able to work, these users need to synchronise sometimes their local database from a network database. i try to do this job automatically. As this network database can be an Oracle Database, Sql Server, Progress, etc, i use an odbc object.  

    Best regards,

    Mad.

    Tuesday, January 5, 2016 1:58 PM
  • Hi Madtotor,

    You could try to make a simple console application to test connection timeout. If it’s working, you would check if any other timeout setting in you code snippet or some configure file.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, January 6, 2016 8:28 AM
    Moderator
  • Hi.

     i found the problem. It seems the odbc connection timeout doesn't manage the network connection timeout in case of the database is on an other server.

      To solve my problem, before connecting to the database, i try a socket connection to the server with the database communication port.

    ' Network check
                If sHost <> "" Then
                    Dim ipHostInfo As IPHostEntry = Dns.GetHostEntry(sHost)
                    Dim ipAddress As IPAddress = ipHostInfo.AddressList(0)
                    Dim remoteEP As New IPEndPoint(ipAddress, sPort)

                    ' Create a TCP/IP socket.
                    Dim sender As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                    Dim result As IAsyncResult
                    ' Connect the socket to the remote endpoint.
                    Try
                        result = sender.BeginConnect(remoteEP, Nothing, Nothing)
                        bRetour = result.AsyncWaitHandle.WaitOne(1250)
                        If Not bRetour Then
                            Return False
                        End If
                    Catch ex As Exception
                        Return False
                    Finally
                        sender.Close()
                    End Try

                End If

                ' Database connection
                dbConRef = New Odbc.OdbcConnection
                dbConRef.ConnectionString = cnxString
                dbConRef.ConnectionTimeout = dbTimeout
                dbConRef.OpenAsync()

      Thanks all for your investigations.

      Best regards.

      Mad.

    • Marked as answer by Madtotor Thursday, January 21, 2016 10:00 AM
    Thursday, January 21, 2016 10:00 AM