Quick Search for:  in language:    
BUG,ASP,SQL,Microsoft,reported,Method,Object,
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
SQL Stats

 Code: 45,316. lines
 Jobs: 126. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login





Latest Code Ticker for SQL.
sp_db_paging_pr imary_key
By Marcus LeBlanc on 1/11


sp_db_paging
By Marcus LeBlanc on 1/11


Beginners pack
By hardik shah on 1/11


Inline Views
By Thivya Prabakaran on 1/6


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Enumerate SQL Servers using SQLDMO and T-SQL

Print
Email
 
VB icon
Submitted on: 6/19/2002 3:23:03 PM
By: Srdjan Josipovic 
Level: Advanced
User Rating: By 1 Users
Compatibility:SQL Server 7.0, SQL Server 6.5 and earlier

Users have accessed this code 3099 times.
 
(About the author)
 
     Microsoft reported BUG : ListAvailableServers Method of the SQLDMO.Application Object Causes Error 0x800A000E . When you execute the ListAvailableServers method of the SQLDMO.Application object from an ASP page, the following error message may occur: Microsoft SQL-DMO (0x800A000E) [SQL-DMO]Not enough storage is available to complete this operation. However, there is some solution to get SQL servers using Client Side script on ASP .<BR><BR>Here is Stored Procedure , which will prepare List of available SQL servers , so you can easy show them in your Web Applications.
 
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: Enumerate SQL Servers using SQL
--     DMO and T-SQL
-- Description:Microsoft reported BUG :
ListAvailableServers Method OF the SQLDMO.Application Object Causes Error 0x800A000E .
WHEN you EXECUTE the ListAvailableServers method OF the SQLDMO.Application object FROM an ASP page, the following error message may occur: 
Microsoft SQL-DMO (0x800A000E) 
[SQL-DMO]Not enough storage IS available to complete this operation. 
However, there IS SOME solution TO get SQL servers using Client Side script on ASP .<BR><BR>Here is Stored PROCEDURE , which will prepare List OF available SQL servers , so you can easy show them in your Web Applications. 
-- By: Srdjan Josipovic
--
--This code is copyrighted and has-- limited warranties.Please see http://
--     www.Planet-Source-Code.com/vb/scripts/Sh
--     owCode.asp?txtCodeId=491&lngWId;=5--for details.--**************************************
--     

CREATE PROCEDURE EnumerateSQLServers
AS
/*
Stored PROCEDURE : EnumerateSQLServers
	Author: Srdjan Josipovic
	Date : June 19 2002
Purpose : Enumerate Available SQL Servers using SQLDMO AND T-SQL 
*/
DECLARE @retval int
DECLARE @result varchar(500)
DECLARE @object int 
DECLARE @objectList int 
DECLARE @src varchar(254)
DECLARE @desc varchar(255)
DECLARE @resultsCount int
DECLARE @counter int
DECLARE @method varchar(255)
--create SQLDMO object
EXEC @retval = sp_OACreate 'SQLDMO.Application', @object OUT
-- check if object was created successfu
--     lly
IF @retval <> 0 
	BEGIN
	EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT 
	SELECT hr=convert(varbinary(4),@retval), Source=@src, Description=@desc
	RETURN
	END
--call method ListAvailableServers() , g
--     et Object_ID for SQLDMO.NameList
EXEC @retval = sp_OAMethod @object , 'ListAvailableSQlServers()' , @objectList OUT
-- error ?
IF @retval <> 0 
	BEGIN
	EXEC sp_OAGetErrorInfo @objectList, @src OUT, @desc OUT 
	SELECT hr=convert(varbinary(4),@retval), Source=@src, Description=@desc
	RETURN
	END
-- Count Servers in the neighborhood
EXEC @retval = sp_OAGetProperty @objectList , 'Count' , @resultsCount OUT
-- error handler again
IF @retval <> 0 
	BEGIN
	EXEC sp_OAGetErrorInfo @objectList, @src OUT, @desc OUT 
	SELECT hr=convert(varbinary(4),@retval), Source=@src, Description=@desc
	RETURN
	END
-- If there are Servers , step into ....
--     .
IF @resultsCount > 0
	BEGIN
		SET @counter = 1
		DECLARE @ServersTbl TABLE (ServerID int IDENTITY ,ServerName varchar(255))
		WHILE @counter <= @resultsCount
			BEGIN
				-- List SQL Server : Name BY Name 
				SET @method = 'Item(' + convert(varchar(3),@counter) + ')'								
				EXEC @retval = sp_OAGetProperty @objectList ,@method , @result OUT
				-- Store data IN the TEMP TABLE
				INSERT INTO @ServersTbl (ServerName) SELECT @result
				-- move TO next record
				SET @counter = @counter + 1
			END
	END
ELSE
	BEGIN
		SET @result = 'No Servers around you'
		INSERT INTO @ServersTbl (ServerName) SELECT @result
	END
-- kill object
EXEC @retval = sp_OADestroy @object
IF @retval <> 0
    BEGIN
    EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT 
    SELECT hr=convert(varbinary(4),@retval), Source=@src, Description=@desc
    RETURN
END

-- OK , List is inside .... SELECT * FROM @ServersTbl GO


Other 1 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Advanced 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

 There are no comments on this submission.
 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | SQL Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.