Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got a windows service that needs to connect to SQL Server databases (SQL Server 2008 R2, Windows Server 2008 R2). This service depends on SQL Server. The problem is when the SQL Server service starts:

Login failed for user 'Database'. Reason: Failed to open the explicitly specified database. [CLIENT: ]

2011-09-20 17:18:29.47 Logon
Error: 18456, Severity: 14, State: 38.

After reading several posts on internet, I checked the auto close property db (false), checked user permissions but can't be this issue because my service works fine few seconds after MSSQLSERVER service start.

Got something strange in my log :

Recovery completed for database database (database ID 8) in 5 second(s) (analysis 909 ms, redo 0 ms, undo 809 ms.) This is an informational message only. No user action is required.

Any idea about this ?

Thanks

share|improve this question

migrated from stackoverflow.com Sep 21 '11 at 4:37

This question came from our site for professional and enthusiast programmers.

3 Answers 3

Perhaps the default database for the service account login is one that takes a significant amount of time to start up (because it is large or has some other issue?). To test this you could change that login's default database to tempdb.

ALTER LOGIN [domain\user] WITH DEFAULT_DATABASE = tempdb;

You could also consider adding TRY/CATCH error handling or waitfor logic to your service so it doesn't fail outright because of a momentary inability to connect (especially during startup).

share|improve this answer

Actually it doesn't fail, exception is handled correctly, but the next process does not start.

In fact, someone gave the solution through this post :

http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/04893862-0b80-416e-a678-da7effdfa7b3

Finally i put some logic to handle this problem (check if db state until it's online)

Thanks for the reply

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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