Click here to Skip to main content
15,896,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I get the following exception stack randomly :

Login failed for user ABC.
MSIL
System.Data.SqlClient.SqlException: Cannot open database  MYDatabase requested by the login. The login failed.
Login failed for user  ABC.
   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 ConnectionFactory.OpenSqlConnection(SqlConnection connection)


I do not often get this exception but it is mostly at the first logon.
For the next logon everything works fine.

Does it have anything to do with loading/unloading of userprofiles or impersonation?

Any specific reason for this? How can I avoid this?
Posted
Comments
Dave Kreskowiak 18-May-11 9:58am    
WHat kind of app is this? Windows Forms or ASP.NET? What does the connection string look like?
priy@ 26-May-11 8:04am    
connection string is "Integrated Security=SSPI;Initial Catalog=MYDatabase;Server=.\\SQLEXPRESS"
priy@ 26-May-11 8:05am    
It is an ASP.net app
Dave Kreskowiak 26-May-11 9:34am    
If you've got any InnerException message, you'll need it. Right now, there isn't enough information to troubleshoot the problem.

I suggest going through http://blogs.msdn.com/b/sql_protocols/archive/2007/05/16/named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error-xxx.aspx.
Dave Kreskowiak 26-May-11 9:35am    
If you've got Named Pipes enabled, try disabling it in the SQL Server and Client and stick with straight TCP/IP.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900