I've seen replying for how to enable the filestream feature by a sql statement. but when the feature is opened, how to restart the sqlserver service instance to made it effects?
2 Answers
You can shutdown SQL Server from T-SQL, but not restart the service. You'll need to do the start using PowerShell (ex: Restart-Service cmdlet) or other command line command like sc.exe.
Or, you could use dbatools PowerShell module do to the whole thing Example for default instance on server1 (error handling to be added):
Enable-DbaFilestream -SqlInstance server1 -FileStreamLevel [1, 2 or 3]
Restart-DbaService -ComputerName server1 -Type Engine
-
I installed a dbatools module with
Install-Module -Name DBATools
, and operated the command above, but it failed as follows log showing:PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> Enable-DbaFilestream -SqlInstance SQLEXPRESS2014 -FileStreamLevel 3
WARNING: [13:33:57][Enable-DbaFilestream] Failure | Error connecting to [SQLEXPRESS2014]: The network path was not
found
PS C:\WINDOWS\system32> Restart-DbaService -ComputerName SQLEXPRESS2014 -Type Engine
WARNING: [13:35:41][Get-DbaService] Failed to resolve or to connect to SQLEXPRESS2014. | No such host is known
Sep 27, 2021 at 5:49 -
SQLEXPRESS2014 is the computer name or the SQL Server instance name? Considering the errors you are getting, I assume it's the instance name. the -SqlInstance parameter value should be <computername>\SQLEXPRESS2014. For the Restart-DbaService command, -ComputerName must be the computer name. The instance name must be specified with parameter -InstanceName Sep 27, 2021 at 17:13
If the only remaining step is to restart the SQL Server service, simply logon to the Windows Server Core machine via Remote Desktop or through the Hypervisor client, and type the following into the console:
net stop "SQL Server (<instanceName>)"
net start "SQL Server (<instanceName>)"
Replace <instanceName> with the name of the SQL Server instance. If the SQL Server is not configured as a Named Instance, then use these commands:
net stop "SQL Server (MSSQLSERVER)"
net start "SQL Server (MSSQLSERVER)"
Be aware that while the SQL Server service is stopped, no clients will be able to connect - you probably want to ensure this change happens during a planned outage window.