Reconnecting to the database.

Posts   
 
    
Pablo
User
Posts: 81
Joined: 21-Mar-2005
# Posted on: 08-Oct-2007 11:03:26   

Hello,

I've run into a problem on our test server. My application is ASP.NET with a SQL2005 server. It runs on a VPS and the SQL server is shared by the hosting company, so not under my control. LLBLGEN runtime fileversion: 2.0.0.061023, selfservice.

After the database is rebooted/restarted while my application keeps running, it seems that my application has trouble reconnecting to the database. I have one thread that polls on a fixed interval if a change is occured in the database. But this action then leads to the following exception:

Event Type: Warning Event Source: ASP.NET 2.0.50727.0 Event Category: Web Event Event ID: 1309 Date: 10/4/2007 Time: 11:35:14 AM User: N/A Computer: PVPS-1591 Description: Event code: 3005 Event message: An unhandled exception has occurred. Event time: 10/4/2007 11:35:14 AM Event time (UTC): 10/4/2007 6:35:14 PM

Event ID: 2ce2ac7b6ddd4677a1dfff938b3caf4d

Event sequence: 10 Event occurrence: 3 Event detail code: 0

Application information:

Application domain: /LM/W3SVC/670395268/Root-1-128359961953906250

Trust level: Full

Application Virtual Path: /

Application Path: C:\Inetpub\wwwroot\kwippo\

Machine name: PVPS-1591

Process information:

Process ID: 36592 

Process name: w3wp.exe 

Account name: NT AUTHORITY\NETWORK SERVICE 

Exception information:

Exception type: SqlException 

Exception message: An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) 

Request information:

Request URL: [http://xx.xx.226.96/Default.aspx](http://xx.xx.226.96/Default.aspx)

Request path: /Default.aspx

User host address: xx.xx.224.133

User: 

Is authenticated: False

Authentication Type: 

Thread account name: NT AUTHORITY\NETWORK SERVICE

Thread information:

Thread ID: 5

Thread account name: NT AUTHORITY\NETWORK SERVICE

Is impersonating: False 

Stack trace:    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, ITransaction containingTransaction, IEntityCollection collectionToFill, Boolean allowDuplicates, IEntityFields fieldsUsedForQuery) at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAction(ITransaction containingTransaction, IEntityCollection collectionToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase1.GetMulti(IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relations, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase1.GetMulti(IPredicate selectFilter) at TopLib.AppMod.Kernel.BL.DequeueManager.ReadQueueDefinitionsFromDB() in C:\VSDEV\TopWebPlatform\TopLib\AppMod\Kernel\BL\EmailOutQueue\DequeueManager.cs:line 29 at TopLib.AppMod.Kernel.BL.DequeueManager..ctor() in C:\VSDEV\TopWebPlatform\TopLib\AppMod\Kernel\BL\EmailOutQueue\DequeueManager.cs:line 22 at TopLib.AppMod.Kernel.BL.TopApp.StartTopApp() in C:\VSDEV\TopWebPlatform\TopLib\AppMod\Kernel\BL\TopApp\TopApp.cs:line 43 at TopLib.AppMod.Kernel.BL.TopApp..cctor() in C:\VSDEV\TopWebPlatform\TopLib\AppMod\Kernel\BL\TopApp\TopApp.cs:line 37

Additional info: the filter I use in the getMulti call on line 29 of the DequeueManager.cs is null.

My current solution is: - stop the webserver application, stop de application pool, start the application pool and then start the webserver application. After that everything works fine again.

My question is: What can/should I do to handle this the proper way?

Paul

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-Oct-2007 11:25:15   

Does you web connection hold any opened connections in memory, that is globaly used?

What happens if you only restart the application pool?

Pablo
User
Posts: 81
Joined: 21-Mar-2005
# Posted on: 08-Oct-2007 11:52:14   

Walaa,

Let me see ... Q1> Does you web connection hold any opened connections in memory, that is globaly used? --> How can I know this? The only connection I make to the database is through the LLBLGEN generated SelfService DLL. I'm sure (though I have to check) that I keep some entities in memory ...

Q2> What happens if you only restart the application pool? --> I don't know, I did not try that. I will try it the next time it occurs. I have not been able to reproduce the situation on my dev pc, so I'll have to wait until next time it occurs (once or twice a week...)?

Paul

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-Oct-2007 12:08:03   

Let me see ... Q1> Does you web connection hold any opened connections in memory, that is globaly used? --> How can I know this? The only connection I make to the database is through the LLBLGEN generated SelfService DLL

I assumed you were using the Adapter model, which enables you to keep the connection open for an adpater to be used for subsequent calls.

I have not been able to reproduce the situation on my dev pc

We will need a repro use case, to be able to inspect the issue.

Pablo
User
Posts: 81
Joined: 21-Mar-2005
# Posted on: 08-Oct-2007 14:36:27   

Walaa, I understand a repro is needed to fix a bug. However, I was hoping for some info on how to deal with connections in self-service model. For example: Is there something that is required to do in my code or configuration, in order to protect the sanity of my application against temporal outage of the DB?

I sure will try to get the problem reproducable.

Paul

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 09-Oct-2007 13:09:03   

Is there something that is required to do in my code or configuration, in order to protect the sanity of my application against temporal outage of the DB?

I can think of a couple of things: 1- Use the latest available version of LLBLGen Pro v.2.0 or upgrade to v.2.5 (free). You are using a year old version of the runtime libraries and many things have been solved since then.

2- Make sure you commit/rollback any transaction that you use.

3- Don't keep entities alive in Session variables or Application variables, especially if they are part of un-commited transaction.

4- And my last advice is to use the Adapter model rather than SelfServicing, this will give you more control on connections & transactions. This will also tackle point 3.

Pablo
User
Posts: 81
Joined: 21-Mar-2005
# Posted on: 09-Oct-2007 14:20:00   

Walaa, Thanx for the advice. Ad 1: Latest version. Yesterday I upgraded the production system, so I'm up to par again with the latest.

Ad 2: Commit and Rollback. Yeah, I can do that more disciplined ;-)

Ad 3+4: SelfService --> Adapter. Humm .... I was hoping to avoid that. But I'll do so ... somewhere soon.

Further .. I'll see how I can reproduce the problem. When that happens I'll get back on the forum.

Thanks for now!

Regards, Paul