Important alert: (current site time 5/23/2013 3:32:06 PM EDT)
 

VB icon

Ping SQL Server Version using SQLDMO

Email
Submitted on: 3/1/2004 5:05:28 AM
By: Joseph Gama 
Level: Intermediate
User Rating: By 2 Users
Compatibility: SQL Server 2000, SQL Server 7.0
Views: 10599
 
     Tests a Server to check for SQL Server running and, if it exists, returns the version. Using SQLDMO’s PingSQLServerVersion Method
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
--**************************************
-- Name: Ping SQL Server Version using SQLDMO
-- Description:Tests a Server to check for SQL Server running and, if it exists, returns the version. Using SQLDMO’s PingSQLServerVersion Method
-- By: Joseph Gama
--
--This code is copyrighted and has-- limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=815&lngWId=5--for details.--**************************************

CREATE PROCEDURE spPing @server NVARCHAR(50)
AS
declare @obj int, @hr int, @SQL nvarchar(4000),
@result int
SET @SQL ='PingSQLServerVersion('+@server+')'
EXEC @hr = sp_OACreate 'SQLDMO.SQLServer', @obj OUT
EXEC @hr = sp_OAMethod @obj, @SQL, @result OUT
EXEC @hr = sp_OADestroy @obj
IF @hr <> 0 
	select 'Error' AS Ping
ELSE
	select CASE @result
		WHEN 0 THEN 'Unknown'
		WHEN 1 THEN 'SQL Server pre 6'
		WHEN 2 THEN 'SQL Server 6'
		WHEN 4 THEN 'SQL Server 6.5'
		WHEN 8 THEN 'SQL Server 7'
		WHEN 16 THEN 'SQL Server 2000'
		ELSE 'Unknown'
		END AS Ping


Other 13 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

3/2/2004 5:51:32 AMMuri.lo

Hi Joseph... with this procedure i must be logged to a SQL Server to check for another instance of SQL Server, right?

Because to execute procedures a server must be running...

And what about if i have an application that wants to check the running status of the main SQL Server (other words, to check the status without being connected to a SQL Server?)

Very nice procedure!
Cheers!
(If this comment was disrespectful, please report it.)

 
3/2/2004 2:52:48 PMJoseph Gama

Hi Muri,
This sp is useful if you want to check other servers in your network, yes you will need to run it from your local SQL Server or some server you have access to.
You can use VB and SQLDMO to achieve the same:
On Error Resume Next
Dim oSQLServer As SQLDMO.SQLServer
Dim sqlversion As SQLDMO_SQL_VER
Set oSQLServer = New SQLDMO.SQLServer
sqlversion =
oSQLServer.PingSQLServerVersion("SERVERNAME")
If Err.Number <> 0 Or sqlversion =
SQLDMOSQLVer_Unknown Then
' You have a problem.
End If
Set oSQLServer = Nothing

Thank you for the feedback.

Peace,

Joseph Gama
(If this comment was disrespectful, please report it.)

 
9/21/2007 3:20:55 AMritesh

Thank u for this code
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.