SQL Server >
SQL Server Forums
>
SQL Server Disaster Recovery and Availability
>
How do I run a command line SQL command in Windows?
How do I run a command line SQL command in Windows?
- I tried to run an ISQL command but I get task or command "not recognized". I need to stop a restore that failed. I am not that familiar with WINDOWS SQL Server. I am using SQL Server Management Studio, SQL 2005.
thanks
Answers
- Use sqlcmd which is the new utility that lets you execute T-SQL commands from the command line. It replaces isql, osql and similar utilities from SQL Server 2000.
- Marked As Answer byAnnettaC Tuesday, November 24, 2009 5:15 PM
- Have you tried to logon to the instance with that account using Management Studio? If you get the same error message then something is wrong with the instance.
Also, are you trying to connect to a named instance? If yes, then you need to use -S servername\instancename.- Marked As Answer byAnnettaC Tuesday, November 24, 2009 5:16 PM
- Try stopping the SQL service.... rename the mdf and ldf files for this db.... start the sql service.... now delete the database....You should then be able to restart your restore.
- Marked As Answer byAnnettaC Tuesday, November 24, 2009 5:14 PM
All Replies
- Use sqlcmd which is the new utility that lets you execute T-SQL commands from the command line. It replaces isql, osql and similar utilities from SQL Server 2000.
- Marked As Answer byAnnettaC Tuesday, November 24, 2009 5:15 PM
- Thanks so much. I will give that a shot.
- Perhaps I am doing something wrong. The sqlcmd tells me that the connection failed and it could be because the server does not allow remote connections. I checked the properties and remote connections are allowed. I also checked to make sure I was using the correct account to log in. Is the correct command:
>sqlcmd -U username -P password -S servername ??
Thanks - Have you tried to logon to the instance with that account using Management Studio? If you get the same error message then something is wrong with the instance.
Also, are you trying to connect to a named instance? If yes, then you need to use -S servername\instancename.- Marked As Answer byAnnettaC Tuesday, November 24, 2009 5:16 PM
You may by in Windows authentication mode. Try
sqlcmd -S servername
or activate SQL Server authentication from Management Studio.
- I can log into the instance from the management studio. That is how I have been doing things, but now I have a restore that errored out, but will not die. It has been running for two days now. I even rebooted thinking it would kill it but it did not. I want to copy the database so I can have one to test my restore on while leaving the original in tact, but I can't even do that while it is in "Restoring" mode.
- Thanks so much to all of you. I figured out, with your help, that I wasn't really giving it the servername. I was only using part of it. It likes the hostname\servername.
- Well. Now that I am in, I cannot kill or reset the restore. I thought just running the restore command with NoRecovery would work. It ran successfully, but my database is still "restoring". I can't do anything to it, because of this restore state. Does anyone know how to reset it?
thanks - Execute
RESTORE <database name> WITH RECOVERY;
- Different, but not desired, results this time. The RESTORE with RECOVERY, gives me an error that the database cannot be recovered because the log was not restored. RESTORE terminated abnormally. HOWEVER, when I look in Management Studio, it is still "restoring". Since it was an empty database, I never bothered to back it up before attempting my restore. Now I can't even delete it to create it again. I really need this database restored from this backup. I know the database backup is a good one, as I was successful in restoring it to a different server but I need it on this one.
Thanks again for all the help.. - Try stopping the SQL service.... rename the mdf and ldf files for this db.... start the sql service.... now delete the database....You should then be able to restart your restore.
- Marked As Answer byAnnettaC Tuesday, November 24, 2009 5:14 PM
- Can you please close this issue and open a new one, with a different subject?