Saturday, May 30, 2009

Start Stop Restart SQL Server from Command Prompt or using Windows Services

SQL SERVER - Start Stop Restart SQL Server from Command Prompt or using Windows Services.


Assalam-o-Alaikum, Dear Fellows here I am going to share with you some of the ways that we use very frequently to start and stop default or named instance of SQL Server.

Click Start>> Run>> type cmd to start command prompt in windows.

To Start default instance of SQL Server
net start mssqlserver

To Start Named instance of SQL Server
net start “SQL Server (mydbsvr)”
net start “SQL Server Agent (mydbsvr)”

– Remember SQL Server Agent can only be start after SQL Server has started. Hence follow the same order that I have mentioned above.
Here “mydbsvr″ is the named instance, this name does not includes my machine name.
Complete name of the instance is SYSNAME\mydbsvr, but here we don’t need complete name we just need instance name.

Figure below is showing how to use net start for start or stop SQL Server default instance;

To Stop default instance of SQL Server
net stop mssqlserver

To Stop Named instance of SQL Server
net stop “SQL Server Agent (mydbsvr)”
net stop “SQL Server (mydbsvr)”

– Remember to Stop SQL Server you first need to stop SQL Server Agent, so first stop SQL Server Agent and then Stop SQL Server, follow the same order as mentioned in the code
The same concept applies here as well, you will not use the complete name of the instance (SYSNAME\mydbsvr), but you will just use instance name without machine name (mydbsvr).

How to Start Stop Restart SQL Server from Windows Services
I will be writing the way to start, stop SQL Server that I use most of the time, whenever I have to copy or transfer my database or logfiles I stop the SQL Server and then copy the database files and then again start the SQl Server Service. For transferring the db files you can also detach and then move to any other location and again attached them but in this way some time detach process takes much time specially when databases are being used by the users. So by stoping the server we can perform this task more easily in comparatively less time. The steps are as described below;

1. Go to Start
2. Go to Run
3. Type
Services.msc
4. Search for SQL Server service (There will be the name of SQl Server whether it is default instance or named instance), double click this service.
5. Check for Startup Type, this should not be disabled. This can be Manual or Automatic. If it is disabled, set it to manual, click apply, click Start the Server get started.

I think no need to explain more its pretty straight forward.


0 comments: