Thursday, March 22, 2012
Cannot open user default database. User login failed.
I'm sorry if this is simple, I'm no DBA but have been tasked with solving this problem...
We have a website that connects via ODBC to SQL Server (2k sp1) and at the moment I am getting back about every other time:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open user default database. Login failed.
So this is NOT happening every single time. Now I have seen Microsoft KB - 307864 and I can see that none of the databases are marked as suspect, the database I am trying to connect to does exist and is attached and, I have run the command to switch the database to multi-user mode.
The probable cause of this problem is that a while ago we had a hard-drive failure and I was forced to reattach some old datafiles (mdf,ldf) as the database. This seemed ok and I can view data etc in enterprise manager no problem.
I have checked for orphaned users and the user I am logging in with from the webpage is not listed.
So does anyone have a clue as to why this is happening, and more frustratingly for me, why is it only happening some of the time.
Thanks for your help, appreciated.
James.Edit your odbc connection and check the default database drop down box...it's probably set to master...|||Brett - Thanks for posting.
Have checked the ODBC settings and the database is not set to master as default .|||Originally posted by JDMoore
Brett - Thanks for posting.
Have checked the ODBC settings and the database is not set to master as default .
What ODBC says if you are trying to test data source under this account?
If everything is fine with ODBC - check your application...|||ODBC says that the connection is fine.
The application has not been changed and has worked fine so I'm virtually certainly it's nothing to do with the program code. The code in question is simply opening a connection to the database.
As I say the error is sporadic presumably an ODBC connection string can either be right or wrong?|||Remotely, but possible, that the default database is in single user mode, and if you login successfully, it means that you're the first one to show up, while when you get an error, then someone's already there (that's to attempt to explain the sporadic nature of the error.) But to be proactive, open EM and go to that database (make sure to register the server with sysadmin privileges.) Check the Options tab of the properties to ensure that the database is not in single user mode. Also, go to Security folder, then to Logins and open properties for the account that the app uses to login and set the default database to master. This is to prevent the situation when a different database was renamed to the one that is specified now as default. And finally, speaking about renamed databases, can you check if it happened recently?|||You might also want to check the connection type in the ODBC. There are times when it doesn't matter whether your using Pipes or Ip but it will test just fine then throw sporadic error messages when actually using the application.
I would try going into the client config button (2nd screen in the ODBC) and if it's set to Pipes then make it IP (port 1433 is default but may have to be changed depending on network) or vice versa.|||Run sql profiler to see what logins are attempting to connect - I am curious to see if the problem is that the iuser account is failing to connect ...|||Thanks for all the suggestions. I am not in until Monday now but when I get in, I will try everything and then get back to you all.
Thanks for posting.|||As always it turned out to be pretty simple...
As I looked further through the code it turned out that the program was looking at this database and then looking at a database on a different server.
When I went to the other server it turned out that THIS database was in single-user mode and hence the sporadic nature of the problem was explained.
Thanks very much for everyone's contribution, probably wouldn't have stumbled over this for ages without your suggestions.
James.
Cannot open user default database. Login failed. (only when IDE is open)
I get the below error only when my IDE open. It connects well when it is found closed.
[SqlException (0x80131904): Cannot open user default database. Login failed.
Login failed for user 'JP\ASPNET'.]
I could solve this by giving the logged in windows user to impersonate under IIS window > WEBSITE > ASP.NET tab > EDIT CONFIG > APPLICATION tab
But I wish someone could give me the proper solution.
I almost tried all from giving ASPNET user as a administrator to configuring the same in Express management tool.
Environment: XP pro, VWD and SQL Express
The problem i think is that u-r user that u r using has default database and that dont exist, to correct that u must go in the property of that user in Sql menagment system and set other default databse for that user..
I hope this will help
Sorry for my bad english
||| I believe that when you have the database opened as "user instance" it can not be opened by more than one application, like Visual Studio and SQL Server Management Express, etc.
Hi jpbiznes,
Could you please explain a little more?
where did you get that error message? From VWD or from IIS ? I guess it is from IIS since if you are using VWD accessing database, the account should be the one which you use to run VWD -- in this case the account won't be ASPNET.
I get the below error only when my IDE open.
There is a possibility that if you have attached your database file from one process, you cannot attach it again from another process. Since one physical database file cannot be attached by two different instances (note we use customer instance in sql2005 express). But in that case the error message should look lik: cannot attach database again since database file is currently in use.
Also, I performed a search through internet and find this KB article which may be helpful to you:
SYMPTOMS
loadTOCNode(1, 'symptoms');Each user has a default database. When you connect to computer that is running Microsoft SQL Server, and you do not specify a login database, the default database is used. However, if the default database is unavailable at the time of the connection, you may not be able to connect. Instead, you receive error message 4062 or error message 4064. The text of the error messages is as follows:
Cannot open user default database
CAUSE
loadTOCNode(1, 'cause');The user default database is unavailable at the time of connection. It is possible that the database:
? Is in suspect mode. ? No longer exists. ? Is in single user mode and the only available connection is already being used by someone else or by something else. ? Has been detached. ? Has been set to the RESTRICTED_USER state. ? Is offline. ? Is set to emergency status. ? Does not have the login account mapped to a user or the user has been denied access. Additionally, the login account may be a member of multiple groups and the default database for one of those groups is unavailable at the time of connection. ? Is part of a database mirror.
http://support.microsoft.com/?id=307864
Hope my suggestion helps
Tuesday, March 20, 2012
Cannot open database requested in login...
I am using ASP to connect to an MS SQL database. The script connects to the database OK and I can retrieve recordset data and add new rows without a problem.
However, when I try to edit a recordset (using the recordset.update command), I get the following error:
Cannot open database requested in login 'andthen_development'. Login fails.
My first thought was that it must be a permissions problem, but that doesn't explain why I can view and add rows, but not edit. Any ideas?
Thanks, Pauldid you try an "Update" command
objCommand.ActiveConnection = objConnection objCommand.CommandText = "Update Table tbl set ..."
Call objCommand.Execute
just see if this works with your login
or try updating with the QA and your login|||then we'll see why the RecordSet.Update doesn't work|||Just tried an "UPDATE TABLE..." command directly and it works fine. However, I have an ASP include file that I use to handle all database functionality centrally. Included in this is the following function:
Function editRow(sqlString, rowParameters)
'#-- UPDATES AN EXISTING DATABASE ROW
'#-- SET UP RECORDSET FOR EDITING A RECORD
Set recordSet = Server.CreateObject("ADODB.RecordSet")
recordSet.CursorLocation = adUseServer
recordSet.CursorType = adOpenForwardOnly
recordSet.LockType = adLockOptimistic
recordSet.Open sqlString, connection, , ,adCmdText
'#-- ITERATE THROUGH rowParameters TO UPDATE ITEM'S FIELDS
Dim rowField
For Each rowField In rowParameters
recordSet(rowField) = rowParameters.Item(rowField)
Next
'#--UPDATE RECORDSET (UPDATE RECORD)
recordSet.Update
End Function
The function accepts an SQL string to identify the row (e.g. "SELECT * FROM...") and a Dictionary object that contains keys relating to field names and values giving the new contents for the row.
This produces an error on the recordset.Update line.
Paul|||maybe it's the cursor location
or one of the option of the recordset
Set recordSet = Server.CreateObject("ADODB.RecordSet")
recordSet.CursorLocation = adUseServer
recordSet.CursorType = adOpenForwardOnly
recordSet.LockType = adLockOptimistic