INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How-to

Find Available SQL Server Using SMO Classes in Visual Basic .NET 2005 Application by PankajBanga
Posted: 14 Dec 05

Introduction

SQL Server 2000 and former included SQL-DMO (Distributed Management Object) a COM based object model, to provide programmatic interface for database management. SQL Server 2005 replaces SQL-DMO with two .NET based object libraries; SQL Server Management Object (SMO) and Replication Management Object (RMO). This article illustrates how to use SMO to programmatically find available instances of SQL Server from Visual Basic .NET 2005 application. You need to reference Microsoft.SqlServer.Smo.dll (.NET assembly) that provides the main SMO classes.

Create a Visual Basic 2005 Console Application
  1. In Visual Basic 2005 IDE click File --> New Project.
  2. In resulting New Project dialog box, in the Project Type pane click Visual Basic node.
  3. In the Templates pane, choose Console Application and click OK.
  4. In Solution Explorer right click ConsoleApplication1 solution and choose Add References from the context menu.
  5. In the resulting Add Reference dialog box, under .NET tab, choose Microsoft.SqlServer.Smo and click OK.
  6. Microsoft.SqlServer.Smo will be added to References node in Solution Explorer under ConsoleApplication1 solution.
  7. Import SMO namespaces with the Imports statement. Imports Microsoft.SqlServer.Management.Smo
  8. Add the following code to Main procedure

    CODE

    Dim dtlSQLServers As DataTable

    ' Get list of all available servers.
    dtlSQLServers = SmoApplication.EnumAvailableSqlServers(False)

    ' Display the list of all available servers and
    ' identify the local sql server.
    For Each drServer As DataRow In dtlSQLServers.Rows
        If drServer("IsLocal") = True Then
            Console.WriteLine("{0} (is the local sql server.)", drServer("Name"))
        Else
            Console.WriteLine(drServer("Name"))
        End If
    Next

    ' Wait
    Console.ReadLine()

      
  9. Run the application. List of available SQL Servers will be displayed, with local SQL Server identified.
EnumAvailableSqlServers public method of SmoApplication class enumerates a list of available instances of SQL Server.

References

For more information on SMO Namespace visit
http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.aspx

For more information on [bSmoApplication[/b] class visit
http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.smoapplication.aspx

For more information on SMO Object Model visit
http://msdn2.microsoft.com/en-us/library/ms162151.aspx

For SMO Object Model Diagram visit
http://msdn2.microsoft.com/en-us/library/ms162209.aspx

Back to Visual Basic (Microsoft) VB.NET FAQ Index
Back to Visual Basic (Microsoft) VB.NET Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close