SunQuest
 
       MS SQL Server
  Home arrow MS SQL Server arrow 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 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
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 / 7
    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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Digging into SQL Server 2000 with WMI Using Visual Basic.NET and VBScript


    (Page 1 of 6 )

    This article further digs into SQL Server 2000 with WMI together with the Visual Basic.NET language and VBScript. It explains various ways of retrieving information from the database.

    I am not enclosing a downloadable solution for this as all the examples in this can be used by extending the downloadable solutions existing in my previous set of articles related to the same category.

    How to retrieve “column” information in SQL Server database using WMI

    Before reading this article, I strongly suggest that you go through my previous set of articles on SQL Server 2000 with WMI on ASP Free.  Those articles include installations, configurations, testing and other valuable information to seamlessly integrate with WMI.  As I covered all the introductory topics of WMI and other technical issues in my previous articles, I will not be repeating them in this article.

    Now we will deal with the information/data/schema available in SQL Server 2000.  In my previous articles, I showed you how to retrieve database and table related information using WMI.  Now we shall dig further by retrieving all column information.  Let us go through the VB.NET script.

    Try
        Dim searcher As New ManagementObjectSearcher( _
            "root\MicrosoftSQLServer", _
            "SELECT * FROM MSSQL_Column WHERE DatabaseName = 'AdventureWorks2000'")

        For Each queryObj As ManagementObject in searcher.Get()
             Console.WriteLine("Name: {0}, TableName: {1}", queryObj("Name"), queryObj("TableName"))
        Next
    Catch err As ManagementException
        MessageBox.Show("Error: " & err.Message)
    End Try

    The most important class note from the above code fragment is “MSSQL_Column”, 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” (column name) and “TableName” (the name of the table to which the column 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_Column WHERE DatabaseName = 'AdventureWorks2000'",,48)
    For Each objItem in colItems
        Wscript.Echo "Name: " & objItem.Name & ", TableName: " & objItem.TableName
    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

    - 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...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway