Остановить sql server на windows 10



October 11, 2016 updated by

Leave a reply »

How to stop a local SQL Server instance from command line or PowerShell? In this tutorial we’ll show you 5 simple ways to stop or start SQL Server service in SQL Server 2016/2014/2012/2005.

Method 1: Stop / Start SQL Server Service from Microsoft Services Console

  1. Press the Windows + R keys to open the Run box. Type services.msc and press Enter.
  2. This will open the Microsoft Services console. Find the service called SQL Server (instant name) and then double-click on it.

    sql-server-service

  3. In the Properties dialog box, you can see that the service name of my SQL Server instance is MSSQL$SQLEXPRESS. From there you can click the Stop button if your SQL Server service is running, or click the Start button to get the service up and running.

    stop-sql-server-service

Method 2: Stop / Start SQL Server Service from Command Line

  1. Open an elevated Command Prompt.
  2. To stop a named SQL Server instance, type the following command. Replace SQLEXPRESS with the instance name.
    net stop MSSQL$SQLEXPRESS

    start-sql-server-command-line

    To start a named SQL Server instance, type:
    net start MSSQL$SQLEXPRESS

Method 3: Stop / Start SQL Server Service from SQL Server Configuration Manager

  1. To get started, you need to open SQL Server Configuration Manager. In Windows Server 2008 or 2003, you can click Start > Programs -> Microsoft SQL Server > Configuration Tools > SQL Server Configuration Manager.
  2. In the left pane of SQL Server Configuration Manager, click SQL Server Services. We can see all services in right pane. Right-click on SQL Server service and you can then select Stop or Start from the context menu.

    sql-server-configuration-manager

Method 4: Stop / Start SQL Server Service from PowerShell

  1. Open the PowerShell as administrator.
  2. You can use the Start-Service cmdlet to stop your SQL Server service. Replace SQLEXPRESS with the instance name.
    Start-Service -Name 'MSSQL$SQLEXPRESS'

    start-sql-server-powershell

    Or use the Stop-Service cmdlet to start your SQL Server service.
    Stop-Service -Name 'MSSQL$SQLEXPRESS'

Method 5: Stop / Start SQL Server Service from SQL server Management Studio

  1. Open SQL server Management Studio and connect to your SQL Server instance.
  2. Right-click on the server in Object Explorer, you’ll have options to Stop, Start, Pause, Resume and Restart your SQL Server service. If we are not already connected, we can’t start a stopped instance.

    stop-sql-server-via-ssms

  • Previous Post: 2 Ways to Reset Forgotten Windows Server 2016 Password
  • Next Post: Reset Windows 10 Password for HP Spectre x360 Laptop

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Have you ever had this issue? You are trying to explore new features of SQL Server or you want to install the latest version for some testing, but SQL Server is a resource hog and kills your the performance of your PC. I have been evaluating SQL Server 2019 including both flavors of Analysis Services. That means I am installing the Developer edition of SQL Server on my laptop (a Yoga 900) running Windows 10.

I have dealt with this issue in the past by opening the services window and setting the Startup Type to Manual and then turning it on when I wanted to work with them. In my current use case, I did not want to have to manage that with a lot of clicks. So, my thought was this should be easy with PowerShell. Of course, nothing is easy when it is not something you do everyday. So I started digging.

I found it is definitely possible but you need to know the steps that matter including making sure that PowerShell will execute the scripts on your PC. So here are the steps and code.

Empowering Your PC to Run Your PowerShell

The first issue is that PowerShell will not execute on your PC until you allow it. You will need to open PowerShell as an Administrator. You can leave the window open once we are done here. The following code will allow code created on your PC to be executed on your PC.

Set-ExecutionPolicy RemoteSigned

Shutting Down SQL Server with PowerShell

I chose to create two PowerShell files that will allow me to execute these steps for all the services I am managing in. In my examples, I have three instances of SQL Server – Data Engine Services, Analysis Services – Multidimensional Model, and Analysis Services – Tabular Mode.

The code required to startup SQL Server is noted below.

Set-Service 'MSSQL$DOWSQL2019' -StartupType Disabled
Stop-Service -Name 'MSSQL$DOWSQL2019' -Force

Let’s break it down. The first line will actually set the StartupType to Disabled. This will prevent it from restarting via a reboot. You will need to be intentional about restarting the service. The second line is the command to stop the service. The “Force” flag will shut down dependant services like SQL Agent if you have that running.

You will need to know the service name. SQL Server Data Engine Services are typically named “MSSQL$” followed by the instance name. If you are using Analysis Services, the naming using “MSOLAP$” as the prefix.

You can run these scripts directly in your PowerShell window. I did this while testing them. I wrote them in Visual Studio Code, but had issues executing them. You may be fine, I wanted to let you know my experience. Once I had my three instances scripted, I saved them in a file called SQLServerOff.ps1.

Turning Them on with PowerShell

The process and the code is similar. You first need to enable the services then start them up.

Set-Service 'MSSQL$DOWSQL2019' -StartupType Manual
Start-Service -Name 'MSSQL$DOWSQL2019' 

I chose the Startup Type “Manual” so I still need to turn them on. It is possible to set that to Automatic if you want it to start up on a reboot for instance. I then saved these in a file called SQLServerOn.ps1.

Running the PS1 Files

There are a couple of options to execute your file. While I was testing and I used the PowerShell window I had open. In order to execute your file replace “YOUR PATH” with the full path to the script.

PS C:\WINDOWS\system32> & "YOUR PATH\SQLServicesOn.ps1"

While a good pattern, I was still looking for the “one-click” solution. Some more digging resulted in me finding the way to execute PowerShell file from a shortcut. I did this by going to the desktop, right clicking an empty space and creating a new, blank short cut. Here is the command you can use for the shortcut:

powershell.exe -noexit -File “YOUR PATH\SQLServicesOn.ps1”

Add the snippet above with the proper path for your code to the shortcut location. Once you have named your shortcut and saved it, you need to open the properties on the shortcut. Go to the advanced settings and run this as Administrator (this will not work without that setting turned on). You can now add the shortcut to a place convenient for you such as your task bar.

While I focused on SQL Server services, this will work other services as well. Enjoy!

Как новичок в SQL Server, вы можете столкнуться с ситуациями, когда вам нужно запустить или остановить службу SQL Server. Будь то сброс пароля sa или устранение неполадок, знание того, как запускать и останавливать SQL Server, является неотъемлемым навыком. В этой статье мы рассмотрим различные методы выполнения этой задачи.

Метод 1: Командная строка

Один из наиболее распространенных способов запуска и остановки SQL Server – через командную строку. Запуская SQL Server в режиме одного пользователя в качестве администратора, вы можете получить доступ к службе. Однако могут возникать ситуации, когда вы сталкиваетесь с ошибками, особенно ошибками операционной системы, указывающими на то, что местоположение журнала ошибок недоступно. В таких случаях повышение привилегий может решить проблему.

Вот пример запуска SQL Server из командной строки:

NET START MSSQLSERVER /m

Для остановки службы вы можете использовать следующую команду:

NET STOP MSSQLSERVER

Метод 2: Менеджер конфигурации

Другой метод запуска и остановки SQL Server – использование Менеджера конфигурации. Этот подход позволяет добавлять параметры, которые вступают в силу при следующем запуске. Для этого выполните следующие действия:

  1. Щелкните правой кнопкой мыши на службе SQL Server и выберите “Свойства”.
  2. Перейдите на вкладку “Параметры запуска”.
  3. Добавьте желаемый параметр в верхнее поле и нажмите “Добавить”.

Имейте в виду, что при запуске SQL Server с использованием этого метода будет разрешено только первое успешное подключение. Другие приложения или клиенты, пытающиеся подключиться, могут занять ваше подключение, поэтому важно быть быстрым и осторожным.

Метод 3: Net Start

Команда “Net Start” – это еще один вариант запуска SQL Server. Она работает аналогично нажатию кнопки “Запуск” в панели служб или Менеджере конфигурации. Вот пример:

NET START MSSQLSERVER /m

Для остановки службы вы можете использовать следующую команду:

NET STOP MSSQLSERVER

Ознакомившись с этими различными методами, вы можете быть уверены, что готовы запускать и останавливать SQL Server по мере необходимости. Кроме того, не забудьте рассмотреть возможность добавления параметров, таких как флаги трассировки и опция -m для чрезвычайных ситуаций.

Помните, что запуск и остановка SQL Server – это навык, который вам может не понадобиться часто, но когда это происходит, это может быть стрессовая ситуация. Практикуя эти методы и понимая различные доступные варианты, вы можете уверенно справляться с такими сценариями.

Счастливого администрирования SQL Server!

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Как установить windows phone вместо андроид
  • Система архивации данных windows server 2016 не работает
  • Установка docker на windows 10 pro
  • Как обновить биос asus на windows 10 компьютере windows
  • Broadcom netlink gigabit ethernet driver windows 10