Connection Timeout on Adapter

Posts   
 
    
arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 01-Feb-2006 17:22:49   

I've started to get strange hangs in one of my 2005.2 adapter apps. In trying to track this down, I was evaluating my code.

I noticed that, I don't find a connection timeout property on the adapter. I'm using SqlServer 2000.

Is it there and I've missed it? Does it use the commandtimeout value? Does it use some other default? Can it be set to a value I like?

pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 01-Feb-2006 19:17:59   

arschr wrote:

I've started to get strange hangs in one of my 2005.2 adapter apps. In trying to track this down, I was evaluating my code.

I noticed that, I don't find a connection timeout property on the adapter. I'm using SqlServer 2000.

Is it there and I've missed it? Does it use the commandtimeout value? Does it use some other default? Can it be set to a value I like?

The connection timeout would be part of the connection string. I think it defaults to 15 seconds.

Or are you perhaps looking for the command timeout?

See this topic in your VS help:


ms-help://MS.VSCC.2003/MS.MSDNQTR.2005OCT.1033/cpref/html/frlrfSystemDataSqlClientSqlConnectionClassConnectionStringTopic.htm

BOb

arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 01-Feb-2006 21:26:26   

The connection timeout would be part of the connection string. I think it defaults to 15 seconds.

Yes, I'm talking connection timeouts, and 15 seconds is the SQLServer default.

I create a new adapter everytime I need to work with the database. It opens itself does the work and closes itself. Each time it does that, it could "need" a different connection timeout.

How can I set that time period (on the llblgen adapter)?

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 01-Feb-2006 22:41:45   

ConnectionTimeout = "Gets the time to wait while trying to establish a connection before terminating the attempt and generating an error."

CommandTimeout = "Gets or sets the wait time before terminating the attempt to execute a command and generating an error."

I am using a shared Database class so that I only need to change the DatabaseSpecificAdapter in one place if I change the database type in the future.

Would this work for you?


' code in your business layer
Using adapter as IDataAccessAdapter = Database.GetAdapter(45)
   adapter.SaveEntity(myEntity)
End Using


' shared Database class in project
Public Class DataBase
    Public Shared Function GetAdapter() As _
  SD.LLBLGen.Pro.ORMSupportClasses.IDataAccessAdapter
        Dim adapter As SD.LLBLGen.Pro.ORMSupportClasses.IDataAccessAdapter = _
 New HTI.Data.DatabaseSpecific.DataAccessAdapter
        Return adapter
    End Function

    Public Shared Function GetAdapter(ByVal Timeout As Integer) As _
SD.LLBLGen.Pro.ORMSupportClasses.IDataAccessAdapter
        Dim adapter As SD.LLBLGen.Pro.ORMSupportClasses.IDataAccessAdapter = _
  GetAdapter()
        adapter.CommandTimeOut = Timeout
        Return adapter
    End Function
End Class

pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 01-Feb-2006 23:06:41   

arschr wrote:

How can I set that time period (on the llblgen adapter)?

You have to change the connection string to have the timeout that you want. Of course, if you change the connection string to have different timeouts you won't get connection pooling.

I guess I don't understand why you would need to use different connection timeouts?

BOb

arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 01-Feb-2006 23:25:09   

ConnectionTimeout = "Gets the time to wait while trying to establish a connection before terminating the attempt and generating an error."

Yes that's the one I'm talking about.

Would this work for you?

I don't see in your code how you set the connection timeout?

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 02-Feb-2006 00:12:39   

Because I did not believe that the ConnectionTimeout is really what you wanted, sorry for not believing you.

In that case you can do some ConnectionString manipulation before you create the adapter. Remember that one of the overloads is New DataBaseAdapter(byval ConnectionString as String)

So it has to be done at the time the Adapter is created.

With the code sample I provided, you could have a central function to manipulate the connection string when creating the Adapter to your hearts content.

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 02-Feb-2006 01:33:46   

Here is a revised version with connection timeout.

It does assume VS2005 and a project settings value for MainConnectionString


Public Class DataBase
    Public Shared Function GetAdapter() As SD.LLBLGen.Pro.ORMSupportClasses.IDataAccessAdapter
        Dim adapter As SD.LLBLGen.Pro.ORMSupportClasses.IDataAccessAdapter = GetAdapter(My.Settings.MainConnectionString)
        Return adapter
    End Function

    Public Shared Function GetAdapter(ByVal ConnectionString As String) As SD.LLBLGen.Pro.ORMSupportClasses.IDataAccessAdapter
        Dim adapter As SD.LLBLGen.Pro.ORMSupportClasses.IDataAccessAdapter = New HTI.FFBL.DatabaseSpecific.DataAccessAdapter(ConnectionString)
        Trace.WriteLineIf(True, "Method Enter: Database.GetAdapter(ConnectionString) ConnectionString=" & My.Settings.MainConnectionString)
        Return adapter
    End Function

    Public Shared Function GetAdapter(ByVal ConnectionTimeout As Integer) As SD.LLBLGen.Pro.ORMSupportClasses.IDataAccessAdapter
        Dim conStrbuilder As System.Data.SqlClient.SqlConnectionStringBuilder = New System.Data.SqlClient.SqlConnectionStringBuilder()
        conStrbuilder.ConnectTimeout = ConnectionTimeout
        Dim adapter As SD.LLBLGen.Pro.ORMSupportClasses.IDataAccessAdapter = GetAdapter(conStrbuilder.ConnectionString)
        Return adapter
    End Function

    Public Shared Function GetAdapter(ByVal ConnectionTimeout As Integer, ByVal CommandTimeout As Integer) As SD.LLBLGen.Pro.ORMSupportClasses.IDataAccessAdapter
        Dim conStrbuilder As System.Data.SqlClient.SqlConnectionStringBuilder = New System.Data.SqlClient.SqlConnectionStringBuilder(My.Settings.MainConnectionString)
        conStrbuilder.ConnectTimeout = ConnectionTimeout
        Dim adapter As SD.LLBLGen.Pro.ORMSupportClasses.IDataAccessAdapter = GetAdapter(conStrbuilder.ConnectionString)
        adapter.CommandTimeOut = CommandTimeout
        Return adapter
    End Function

End Class


arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 02-Feb-2006 13:34:07   

Here is a revised version with connection timeout.

Thanks. The project these hangs are happening in are in vs2003 still. I'll see if I can modify your code to work.

I wanted to verify that llblgen uses the default connection timeout (15 seconds for SQLServer) and not 0 (which I think would be wait forever).