0

I have an ASP.NET v2 website which uses NHibernate for ORM. My current architecture is not that great and I will be changing it after reading some best practices but I wish to still try and figure out my current problem.

I have a login screen which creates a ISessionFactory with the connection string set appropriately to the user name and password entered. The SessionFactory is then stored in HttpRuntime.Cache (all objects stored in the HttpRuntime.Cache have an expiration of 30 minutes which is not ideal and may cause issues but hopefully is not relevant to this particular case).

Whenever a data query is made the application tries to retrieve a Session from HttpContext.Current. The first time this occurs no Session is present so one is created from the SessionFactory and stored for future reference. The same Session is therefore is used throughtout the application which is not ideal I believe and it is not explicity closed after each operation.

There have been various issues with the application including timeouts which may be associated with not closing connections after each operation. An error that has recently appeared is:

Message: Login failed for user 'myusername'.
Type: System.Data.SqlClient.SqlException
Source: .Net SqlClient Data Provider
Stack Trace:    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)

This is only after a few minutes of using the application so should not be related to the use of HttpRuntime.Cache. The username in the exception (myusername) does not match the user specified in the connection string! Does anyone have any idea of what could cause this. I was thinking of ConnectionPooling but understand that the connection is made from a pool keyed on user name and password so it shouldn't confuse users.

I am changing the application to use an IHttpModule to create a session per request which will be explicity closed after each operation but I would still like to know what causes the current problem.

3
  • I'm not sure what you mean - I have accepted answers when I have implemented them and know them to be correct. Others split into different categories - suggestions for a library where an accepted answer is not applicable, possible solution but with pending questions, no valid answer. According to the StackOverflow FAQ it is not always applicable to close a question - what would you suggest I do for my open questions? Feb 12, 2010 at 22:47
  • Pick the best answer? lol...it doesn't hurt to vote once in a while also. What do you think motivates people to give answers?
    – dotjoe
    Feb 12, 2010 at 22:58
  • You are right - I have added comments, up voted and closed questions where appropriate. Feb 14, 2010 at 13:31

1 Answer 1

0

looks like an issue with your sql server login credentials. and listen to Mattias!

2
  • The SQL connection is created correctly for the user that logs in, say john.smith. At a certain point an error is occuring and the exception is raised like in the original question but stating a different login name e.g. myusername Feb 14, 2010 at 13:30
  • but it is a SQL login exception, not a user login issue. so something, somewhere, is trying to connect to the SQL server with the wrong credentials, right? can you post the full stack trace? Feb 15, 2010 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.