Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL using Command Prompt - sqlcmd

Author  Topic 

dirtyfishtank
Starting Member

8 Posts

Posted - 2012-01-03 : 06:03:20
Hi all.
I have installed a sample database called 'books' running on MS Server Management studio express on my personal pc. The database works fine, however I would like to be able to run scripts thru a cmd prompt using sqlcmd. I am the administrator and owner of the server, computer and the db, but when I run
 sqlcmd -d books
I get this error:

Msg 4060, Level 11, State 1, Server MYNAME-PC, Line 1
Cannot open database "books" requested by the login. The login failed.

When I use this command
sqlcmd -d books -U <username>
I get prompted the password but gives me the error: Msg 4060, Level 11, State 1, Server MYNAME-PC, Line 1
Cannot open database "books" requested by the login. The login failed.

This happens even when I run cmd as administrator. I set up the database to use windows authentication. I'm not sure I chose a password for server authentication. Is there an easy fix for this?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-03 : 06:21:10
you're running sqlcmd under your admin windows account?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dirtyfishtank
Starting Member

8 Posts

Posted - 2012-01-03 : 06:50:12
yes I am. Is there a way to recover the sql server password? Could that be what is causing the problem?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-03 : 07:33:33
hmm..which sql server password? you're using trusted connection right?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-03 : 07:54:45
If you are using SQLExpress, the server name would be MYNAME-PC\SQLExpress. So try:
sqlcmd -d books -S MYNAME-PC\SQLExpress
Go to Top of Page

dirtyfishtank
Starting Member

8 Posts

Posted - 2012-01-03 : 08:07:11
That works. Thanks!
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-03 : 14:21:08
-E

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -