sqlserver Cannot Open User Default Database

sqlserver Cannot Open User Default Database

To update a database that wasn't being used yet I disconnected it from sql, uploaded the changes and then couldn't get back into the database. The server I'm on had two to login to, "sharepoint" and "sbsmonitoring". The database was in "sharepoint". I can no longer access "sharepoint" but can access the sbsmonitoring". I've determine from the posts I've read that I can't access the "sharepoint" server because the default database no longer exsists in that database. I've found code to reset that,

c:\> sqlcmd -S AIR\SQLEXPRESS -d master

Where AIR is the name of my machine and SQLEXPRESS the name of the SQL Server instance.

In the sqlcmd prompt I put the following:

1> alter login [AIR\alvaro ramirez] with default_database = master

Where AIR is my machine's name

Another problem I was having was the missing []. Because the username I have in my computer has a space, the [] are required.

2> go

3> exit

How ever when I run this I receive the error, "Msg 15151, Level 16, State 1,' Server Machname\username', because it does not exist or you do not have permission."

I have administrator rights, and ran the dos prompt as administrator. I believe I'm entering the domain wrong. Here is my actual code I run,

c:\>sqlcmd -S machinename\sharepoint -d master

>1 alter login [machinename\domain\username] with default_database=master

>2 go

Line 1 is where I receive the error. Does anyone see the problem with my code?

Try the below script,

alter login [domain\username] with default_database=master

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright