Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 SQL Server start time

Author  Topic 

Wanderer
Master Smack Fu Yak Hacker

1168 Posts

Posted - 2002-03-19 : 10:54:05
Hi guys,

I'm trying to find a way to get the start time for SQL server on a server, via SQL from a remote machine. That is to say, I would like to try and have machine A find out when SQL started on machine B (and eventually on all specified machines - that list will reside in a table local on machine A).

I haven't found a clean way of doing this. so far the best I could come up with is:

Select @@servername as Server_Name,login_time from master..sysprocesses
where spid = 1

There got to be a better way, surely ?

TIA

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-03-19 : 20:01:05
I'm so annoyed, I would have thought there was a cool way to do that, and I can not find one

The way you are doing it seems to work, the only other thing I can suggest is a proc that runs on startup that logs the server starting in a table somewhere.



Damian
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2002-03-19 : 20:33:47
I have been playing with @@Idle and @@CPU_Busy...

They both return milliseconds since last started...

I wold have thought the (@@Idle + @CPU_Busy) would give you the total number of milliseconds since start....

Not even close apparently......



DavidM

Tomorrow is the same day as Today was the day before.
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-03-19 : 20:40:13
It is in the event log, if you wrote a com object that would read the event log and found the last MSSQLSERVER entry, then called that from a stored proc, that would do it....messy though.

Damian
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-03-19 : 20:48:27
Or, you could use the xp_readerrorlog stored procedure. It's undocumented, but it's in Ken Henderson's

The Guru's Guide to Transact-SQL

Damian should have something for you in a minute or so that filters out the excess info it reports.

Go to Top of Page

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2002-03-19 : 20:49:03
Isn't there an extended stored proc called xp_readlog that will read the log file? That should have the start time.

===============================================
Creating tomorrow's legacy systems today.
One crisis at a time.
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2002-03-19 : 20:51:41
Rob, Graz,

Wanderer wants a CLEAN solution..

I take that to mean..Documented and (in this case) permissions neutral...

DavidM

Tomorrow is the same day as Today was the day before.
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-03-19 : 20:53:03
OK, its not ultra clean, but how is this.



Create Table #Logs (
Errorlog VarChar(2000),
ContinuationRow int
)
INSERT Into #Logs
Exec Master..xp_readerrorlog

SELECT
ERRORLOG,
Cast(Substring(ERRORLOG, 1, 22) as DateTime) [Start Date],
DateDiff(n, Cast(Substring(ERRORLOG, 1, 22) as DateTime), GetDate()) as
[Uptime (Minutes)]
FROM
#Logs
WHERE
ERRORLOG Like '%SQL Server is Starting%'


DROP Table #Logs



Thanks Rob!

Damian

Edited by - merkin on 03/19/2002 21:00:39
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-03-19 : 20:55:12
quote:
Rob, Graz,

Wanderer wants a CLEAN solution..

I take that to mean..Documented and (in this case) permissions neutral...



We're open to whatever suggestions you have David...

Go to Top of Page

Wanderer
Master Smack Fu Yak Hacker

1168 Posts

Posted - 2002-03-20 : 03:48:46
Alright!!!

I knew there was some kind of xp to read logs, but BOL just laughed at me...

maybe I should buy

The Guru's Guide to Transact-SQL

*grin*

This definitely is what I was looking for. It is clean enough for me (kinda a muddy guy anyway), and now I can use this to do more than just Start Time!

TAG (Thanx Again Guys)



Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-03-20 : 05:53:40
Of course you should buy it!

http://www.sqlteam.com/store.asp


I'm glad that helped.

Damian
Go to Top of Page

Glockenspiel
Yak Posting Veteran

50 Posts

Posted - 2002-06-25 : 11:28:52
See http://www.sqlteam.com/Forums/topic.asp?TOPIC_ID=17104

Go to Top of Page
   

- Advertisement -