MS SQL Server
  Home arrow MS SQL Server arrow Can We Manage SQL Server 2000 With WMI and...
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

Can We Manage SQL Server 2000 With WMI and Visual Basic.NET?
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 7
    2005-11-23

    Table of Contents:
  • Can We Manage SQL Server 2000 With WMI and Visual Basic.NET?
  • How do you “start” or “stop” the MS SQL Server 2000 service?
  • Can we retrieve all logins available in SQL Server 2000?
  • How do you change the password of an SQL Server Login using WMI?
  • Summary

  • 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


    Can We Manage SQL Server 2000 With WMI and Visual Basic.NET?


    (Page 1 of 5 )

    The previous article mainly concentrated on fetching information available in SQL Server 2000. This article explains how to manage SQL Server 2000 using WMI together with Visual Basic.NET language.
    A downloadable file for this article is available here

    The sample downloadable solution (zip) is entirely developed using Visual Studio.NET 2003 Enterprise Architect on Windows Server 2003 Standard Edition together with SQL Server 2000 Enterprise Edition.  But, I am confident that it would work with other versions of Windows (which support .NET 1.1) versions as well.

    Is SQL Server 2000 service started on your computer?

    I strongly suggest you refer to my previous article “Can we integrate Visual Basic.NET, SQL Server 2000 and WMI?”  before proceeding through this article.  In my previous article, I mainly focused on retrieving SQL Server database objects using WMI. Now, in this article, I shall introduce you to managing a SQL Server database using WMI together with Visual Basic .NET. 

    Before managing the database, generally every developer would check whether the instance of SQL Server started running or not.  Everyone knows how to check it using the Service Manager available in SQL Server. Now we shall achieve almost the same thing using the following code:

    Private Sub btnStatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStatus.Click
            Dim PrivateLateBoundObject As ManagementObject
            'PrivateLateBoundObject = New ManagementObject(Nothing, New ManagementPath("\\SERVER\root\CIMV2:
    Win32_Service.Name=""MSSQLServer"""), Nothing)
            PrivateLateBoundObject = New ManagementObject(Nothing, New ManagementPath("\\SERVER\root\MicrosoftSQLServer:
    Win32_Service.Name=""MSSQLSERVER"""), Nothing)
            MessageBox.Show(CType(PrivateLateBoundObject("Started"), Boolean))
            PrivateLateBoundObject.Dispose()
        End Sub

    From the above code, you can understand that I am creating an object (PrivateLateBoundObject) based on the “ManagementObject” class.  The “ManagementPath” starts with “\\yourhostname”.  There exists a WMI class called “Win32_Service” within the “MicrosoftSQLServer” namespace (which comes onto the scene after you installed the “WMI SQL Server Administration Provider”). 

    In another scenario, you need not use only the “MicrsoftSQLServer” namespace in WMI; you can directly use “CIMV2” as well (as commented in the coding).  If you don’t install “WMI SQL Server Administration Provider” (as specified in my previous article), you will not be able to work with the “MicrosoftSQLServer” namespace.  But you would still be able to work with “CIMV2”, which comes with default installation of the Windows OS.

    There exists a WMI property called “Started” (of type Boolean) which is used to check the status of the Microsoft SQL Server 2000 service.  It returns “true” if the service is running (or started) or else returns “false” if it is not.

    More MS SQL Server Articles
    More By Jagadish Chaterjee


       · Hello everybody...now you can manage SQL Server as well...try the article and...
     

    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-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek