August 29, 2013 at 5:04 am
I would like to add data like time in a table in sqlserver when sqlserver machine is started or shutdown.
August 29, 2013 at 5:25 am
To write data when the instance is started you can create a job with a schedule to be executed "Start automatically when SQL Agent starts". Maybe you should include some logic to read the SQL log and read the time the SQL Engine was started. This prevents from false entries when only the SQL Agent service was restarted.
There is no way of writing data when an instance is shutting down. When an instance is shutting down all activities are aborted. Look it at this way: when a power failure occurs the server is shut down immediately, there is no time to do anything.
August 29, 2013 at 5:28 am
HanShi (8/29/2013)
To write data when the instance is started you can create a job with a schedule to be executed "Start automatically when SQL Agent starts". Maybe you should include some logic to read the SQL log and read the time the SQL Engine was started. This prevents from false entries when only the SQL Agent service was restarted.There is no way of writing data when an instance is shutting down. When an instance is shutting down all activities are aborted. Look it at this way: when a power failure occurs the server is shut down immediately, there is no time to do anything.
You could also execute a stored procedure on startup.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
August 29, 2013 at 5:32 am
If you want logging of the startup and shutdown time of an instance, consider the following:
You can setup another server/instance and poll the connectivity to the required instance(s) every minute or so. Write the results of this polling to a table. This way you will have logging of the availability of the required instance(s). You can then create queries/reports to report about the percentage uptime over a specific period of time.
August 29, 2013 at 5:34 am
Koen Verbeeck (8/29/2013)
You could also execute a stored procedure on startup.
That's new to me. Thanks, I learned something 😉
August 29, 2013 at 10:28 pm
harsimranjeetsinghwasson (8/29/2013)
I would like to add data like time in a table in sqlserver when sqlserver machine is started or shutdown.
This information is recorded in the SQL Server logs and you can get the information pretty easily using sp_ReadErrorLog. I wouldn't add what you're taking about to the startup because if someone screws up and deletes the proc or the related table, it could cause SQL Server to fail. Further, adding a startup procedure won't record when the server shuts down.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 30, 2013 at 3:38 am
HI Koen,
Do i need to schedule the same as i tried to add my procedure created in master database but logging the time in table of other user defined database on same server , not reflecting any data. :doze:
August 30, 2013 at 3:50 am
harsimranjeetsinghwasson (8/30/2013)
HI Koen,Do i need to schedule the same as i tried to add my procedure created in master database but logging the time in table of other user defined database on same server , not reflecting any data. :doze:
What are you doing inside the stored proc?
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
August 30, 2013 at 4:03 am
:unsure: I guess table to log data should also be created in master only , because when i did so i started logging data.
One thing i would like to ask is about "OFF" value for option "startup" in sp_procoption. Is that related to service stop event as when i did the proc called has not update row with timestamp.
August 30, 2013 at 4:13 am
I am loggin my checkin and checkout time from office in a table , checkin is working fine but checkout depends when i shutdown my system any clue for same and last question i ask about "off" , is cleared to me and seems like it is basically related to procedure on and off on startup event .
August 30, 2013 at 7:20 am
harsimranjeetsinghwasson (8/30/2013)
:unsure: I guess table to log data should also be created in master only , because when i did so i started logging data.One thing i would like to ask is about "OFF" value for option "startup" in sp_procoption. Is that related to service stop event as when i did the proc called has not update row with timestamp.
No. Like I said, I believe the only way you'll be able to record the "OFF" is to get it from the SQL Logs using sp_ReadErrorLog.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 30, 2013 at 11:13 am
So when you finish for the day you shut down SQL? If this is just to record that then how are you shutting down SQL?
If just through the services applet, command window or SSMS, replace this with a .bat file to run which uses sqlcmd to log an entry in your table, and then does a net stop on the SQL service. Use this .bat file to stop SQL.
this could also be done via powershell.
---------------------------------------------------------------------
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply