The ASP Emporium
Free Active Server Applications and Examples by Bill Gearhart
Online since Friday January 7, 2000

 home > code > classic asp apps > SQLServerTools Object

enter a phrase to search:(advanced search)


 h o m e 

 w h a t 's  n e w 

 a l l   c o d e 
  .net:
    • Fundamentals
    • C# Classes
  classic asp:
    • Code Library
    • ASP Apps
  general:
    • Tutorials
    • SQL

 d o w n l o a d s 

 u s e r   f o r u m s 

 l i n k s 

 s e a r c h 

 s u p p o r t 


SQLServerTools Object

This one's like a double whammie! Welcome to the world of hard core SQL Server stored procedures and to the NextRecordset method of ADO's recordset object... Before we go on, this requires SQL Server. WON'T WORK WITH ACCESS.

That said, the goal for this example was easy... Get a list of all current tables in the database created by your's truly, get a list of dependent stored procedures for each table and do it all in a stored procedure! Easy...

There are basically 2 parts to this example. The calling application (a VBScript class called SQLServerTools) and the SQL Server stored procedure: sp_Admin_ExampleTablesDependencies (included with the class). The VBScript class is easy and contains only 1 method. That method is a great example of how to use the NextRecordset method of ADO to capture a second (or 50th) recordset returned by a procedure. For example, did you know this was valid SQL:

"SELECT * FROM table1;SELECT * FROM table2;"

Well it is, SQL Server knows that this statement should produce two separate and distinct recordsets however if you execute that and don't use NextRecordset, you will only get that first RS back. The stored procedure I wrote to do all the work is the second part of the example. That procedure returns (2 * num of tables) recordsets which is variable and based on the number of tables found in sysobjects for your particular db. Bottom line, that procedure always returns more than 1 recordset.

Right now, as you read this, I estimate that the procedure returned as many as 30 recordsets that were looped through with NextRecordset... But that's not the real magic. The class only exists to call the procedure and work with it's results. The stored procedure itself does all the work.

I've commented both the app and the stored procedure to the max but I'll give you an overview of the stored procedure... The stored procedure uses a cursor to loop through the records of a recordset returned by the system table: sysobjects. The process used is almost the same as using ADO to manipulate a recordset but right in the db itself... this means huge speed bonus and, by writing a stored procedure, all that logic is forever contained within and isn't spilled out into the class where it doesn't belong.

So anyways, while the procedure is looping through each table returned by sysobjects, it's simultaneously calling the system stored procedure: sp_depends. sp_depends is a handy function that returns a recordset of names representing every stored procedure that references the entered table! sp_depends can be used on any object, not just tables, but that is another discussion for another day...

The output of sp_Admin_ExampleTablesDependencies is below: Every table used in ASP Emporium examples and the stored procedures that work with those tables... Pretty slick, eh? and only the tip of the iceburg...


 autoResponder 
  sp_AddMailRecip    (stored procedure)  
  sp_Admin_ClearAutoResponder    (stored procedure)  
  sp_GetMailRecips    (stored procedure)  
  sp_RemMailRecip    (stored procedure)  
  sp_RemMailRecipByID    (stored procedure)  

 dayPlannerAddresses 
  sp_addUsrAddr    (stored procedure)  
  sp_Admin_ClearDayPlannerAddresses    (stored procedure)  
  sp_getAllUsrAddr    (stored procedure)  
  sp_getUsrAddr    (stored procedure)  
  sp_getUsrAddrByLast    (stored procedure)  
  sp_modUsrAddr    (stored procedure)  
  sp_remUsrAddr    (stored procedure)  

 dayPlannerEvents 
  sp_addUsrEvent    (stored procedure)  
  sp_Admin_ClearDayPlannerEvents    (stored procedure)  
  sp_getUsrEvents    (stored procedure)  
  sp_remUsrEvent    (stored procedure)