INTELLIGENT WORK FORUMS FOR COMPUTER PROFESSIONALS
Come Join Us!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- Turn Off Ad Banners
- 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.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site

(Download This Button Today!)
Member Feedback
"...I have tons of books, have book marked tons of tutorials, which have helped, but this forum has answered those "impossible to find" solutions. I am thrilled with this site..."
Geography
Where in the world do Tek-Tips members come from?
|
Visual Basic(Microsoft) -VB.NET 2002-2008 FAQ
|
How-to
|
Find Available SQL Server Using SMO Classes in Visual Basic .NET 2005 Application
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
- In Visual Basic 2005 IDE click File --> New Project.
- In resulting New Project dialog box, in the Project Type pane click Visual Basic node.
- In the Templates pane, choose Console Application and click OK.
- In Solution Explorer right click ConsoleApplication1 solution and choose Add References from the context menu.
- In the resulting Add Reference dialog box, under .NET tab, choose Microsoft.SqlServer.Smo and click OK.
- Microsoft.SqlServer.Smo will be added to References node in Solution Explorer under ConsoleApplication1 solution.
- Import SMO namespaces with the Imports statement. Imports Microsoft.SqlServer.Management.Smo
- Add the following code to Main procedure
CODEDim 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()
- 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 2002-2008 FAQ Index
Back to Visual Basic(Microsoft) -VB.NET 2002-2008 Forum
My FAQ Archive
Email This FAQ To A Friend |
|
 |
|