I have a running SQL Server image on Docker, however I need to enable SQL Server Agent to run some jobs, but I have not succeeded. The main problem is that the container has quite a few databases and settings that need to be maintained. The command "docker run -e" MSSQL_AGENT_ENABLED = true ... "" is not useful to me because it creates a new container and I would lose the current configuration.
I used the following commands that allowed to enable the interface, but when running the job I get an error that SQL Server Agent is not enabled
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Agent XPs',1
reconfigure
The error generated when executing the job is the following
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo) SQLServerAgent is not currently running so it cannot be notified of this action. (Microsoft SQL Server, Error: 22022)
I tried to start the SQL Server Agent with the command EXEC xp_servicecontrol N'START ', N'SQLServerAGENT'
, but it generates another error
StartService() returned error 1053, 'The service did not respond to the start or control request in a timely fashion.'
The question would be, how can I enable the SQL Server Agent in the container that is already running to be able to schedule jobs
3条答案
按热度按时间lh80um4z1#
If you've already created a Docker container with something like SQL Server 2019 Developer edition:
With reference to Configure SQL Server on Linux with the mssql-conf tool, get a root shell in the container:
Then enable SQL Agent in the configuration file and restart the SQL Server service:
If you get an error message such as
systemctl: command not found
then just stop and start the container for the changes to take effect.nnsrf1az2#
From outside the container go into terminal by doing the following:
The password will not be of the container.
Next elevate yourself to superuser:
Next enable sqlagent by changing the configuration file:
Now exit the container by typing exit once to logout from root and next to exit from the container
Finally restart the the docker container that has your microsoft sql server instance running
(in this case tagged sql1)
N.B. Within SQL Management Studio you need to right click the SQL Server Agent Icon and refresh to verify it is up.
Note you no longer have to do this if you enabled SQL server agent with the flag when initialising the container:
jk9hmnmh3#
For anyone using Docker Compose, it's much easier to just add a flag to the yaml environment:
Then just down and up the container again.
More info at Microsoft.com
Credit goes to Mickeybyte: https://stackoverflow.com/a/76182745