MS SQL Server
  Home arrow MS SQL Server arrow Page 4 - Digging into SQL Server 2000 with WMI Usin...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

Digging into SQL Server 2000 with WMI Using Visual Basic.NET and VBScript
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 11
    2005-11-30

    Table of Contents:
  • Digging into SQL Server 2000 with WMI Using Visual Basic.NET and VBScript
  • How to retrieve “database file” information in SQL Server using WMI
  • How to retrieve “view”, “stored procedure”, “user defined function”, and “trigger” information in SQL Server using WMI
  • How to retrieve all the parameters of “stored procedure” using WMI
  • How to add a primary key to a table using WMI
  • Can we rename a database using WMI?

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Digging into SQL Server 2000 with WMI Using Visual Basic.NET and VBScript - How to retrieve all the parameters of “stored procedure” using WMI


    (Page 4 of 6 )

    Some of the stored procedures in the database may have parameters.  Those parameters would be either IN or OUT or IN OUT type of parameters.  IN stands for INPUT parameter, and OUTPUT stands for OUTPUT parameter. We can retrieve that information using WMI with the following code in VB.NET.

    Try
        Dim searcher As New ManagementObjectSearcher( _
            "root\MicrosoftSQLServer", _
            "SELECT * FROM MSSQL_StoredProcedureParameter")

        For Each queryObj As ManagementObject in searcher.Get()

             Console.WriteLine("-------------------")
             Console.WriteLine("DatabaseName: {0}", queryObj("DatabaseName"))
             Console.WriteLine("StoredProcedureName: {0}", queryObj("StoredProcedureName"))
             Console.WriteLine("Name: {0}", queryObj("Name"))
             Console.WriteLine("Output: {0}", queryObj("Output"))
        Next           
             Catch err As ManagementException
        MessageBox.Show("Error: " & err.Message)
    End Try

    The most important class note from the above code fragment is “MSSQL_StoredProcedureParameter”, which is a WMI class especially available for SQL Server 2000.  It has several properties to give us increasing amounts of  information.  At the moment, I chose only “name” (stored procedure parameter name), “StoredProcedureName” (name of the stored procedure to which it belongs), “output” (true or false, which denotes whether or not it is an output parameter) and “DatabaseName” (to which database it belongs). 

    The VBScript version of the same would be as follows:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftSQLServer")
    Set colItems = objWMIService.ExecQuery( _
        "SELECT * FROM MSSQL_StoredProcedureParameter",,48)
    For Each objItem in colItems
        Wscript.Echo "----------------------"
        Wscript.Echo "DatabaseName: " & objItem.DatabaseName
        Wscript.Echo "StoredProcedureName: " & objItem.StoredProcedureName
        Wscript.Echo "Name: " & objItem.Name
        Wscript.Echo "Output: " & objItem.Output
    Next

    More MS SQL Server Articles
    More By Jagadish Chaterjee


       · hello guys...WMI with SQL Server has gone to further depth..have the article and...
       · I want to connect to remote sql server by using vb.net code. I am using...
     

    MS SQL SERVER ARTICLES

    - Windows Server 2008 as a Workstation OS
    - An Overview of Windows Server 2008 R2
    - LINQ to MySQL, Oracle and PostgreSQL Provide...
    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek