Can We Integrate Visual Basic.NET, SQL Server 2000 and WMI? - How to connect to SQL Server 2000 using WMI
(Page 2 of 4 )
First of all, you need to install “WMI SQL Server Administration Provider” on an existing instance of SQL Server 2000 (if not installed). This is not part of the default or custom installation. You need to install it separately from SQL server installations. You can find the “WMI SQL Server Administration Provider” installation files at the “x86\other\wmi” path of your SQL Server 2000 installation CD. To be frank, I really didn’t check this on SQL Server 7.0. So, my focus will always be on SQL Server 2000 in this article.
Once it is installed (which is as simple as winzip installation), you can directly work with my downloadable solution. The first button (captioned “version”) within the form tries to give you the SQL server version you installed on your computer. If you can get it, you can confirm that WMI works with your version. Let us go through the code I wrote:
Private Sub btnCaption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCaption.Click
Dim PrivateLateBoundObject As ManagementObject
PrivateLateBoundObject = New ManagementObject(Nothing, New ManagementPath("\\server\root\MicrosoftSQLServer:
MSSQL_SQLServer.Name=""(local)"""), Nothing)
MessageBox.Show(PrivateLateBoundObject("VersionString"))
PrivateLateBoundObject.Dispose()
End Sub
From the code above, 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 “MSSQL_SQLServer” within the “MicrosoftSQLServer” namespace (which comes onto the scene after you installed the “WMI SQL Server Administration Provider”).
The “(local)” says that I am trying to connect to my “local instance” within the same host name I provided. There exists a WMI property called “VersionString” which is used to retrieve the version information of SQL Server 2000 you installed on your computer. You should get an output (Message box) something like the following figure.

Next: How to retrieve “Databases” information in SQL Server instance >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee