MS SQL Server
  Home arrow MS SQL Server arrow Page 3 - 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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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: 4 stars4 stars4 stars4 stars4 stars / 9
    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 “view”, “stored procedure”, “user defined function”, and “trigger” information in SQL Server using WMI


    (Page 3 of 6 )

    “View” is something like a logical and virtual table.  Every view gets accompanied with a SELECT query.  We can even retrieve that information using WMI, by using the following code in VB.NET.

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

        For Each queryObj As ManagementObject in searcher.Get()

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

    The most important class note from the above code fragment is “MSSQL_View”, 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” (view name), “Text” (the SELECT query for the view) 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_View",,48)
    For Each objItem in colItems
        Wscript.Echo "DatabaseName: " & objItem.DatabaseName
        Wscript.Echo "Name: " & objItem.Name
        Wscript.Echo "Text: " & objItem.Text
    Next

    If you replace “MSSQL_View” with “MSSQL_StoredProcedure” in the above two code fragments, you will get the list of all “StoredProcedures” complete with the related coding. Similarly, you can use “MSSQL_UserDefinedFunction” to get the list of all “stored user defined function” available in the database along with coding. You can also use “MSSQL_trigger” to get the list of all “triggers” available in the database along with coding. 

    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

    - 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
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT