Friday, July 14, 2006 5:24 PM
Mohamed Meshref
First SMO Article, what's SMO?
I promised few days ago that I'll be blogging frequently on this blog, writing several articles about SQL Server Management Tools and Libraries.
I'll start with SMO (SMO stands for SQL Server Management Objects), which is simply a group of classes to control SQL Server and do whatever you could make with traditional T-SQL.
During the upcoming articles, I'll go through all SMO classes and in every article I'll try to cover one class with examples on it.
For now, let's begin with the main class which is nearly used by all SMO classes: Server class
This class simply encapsulate the SQL Server instance, and includes many utility APIs for dealing with SQL Server instance, like getting the version, getting all attached databases, tables in each database, etc.
In this example, I'll be using SMO version 9.0.2047.0 (SQL Server 2005 + SP1), so the requirements for running this sample, are:
- .Net framework version 2.0
- Microsoft SQL Server 2005 with Client Tools + Microsoft SQL Server 2005 Service Pack 1
In this article, we'll do a small sample to enumerate some type of objects of the SQL Server instance:
- Databases.
- Views.
- Tables.
- Columns.
- Indexes.
- Keys.
- Triggers.
- Functions.
- Stored Procedures.
This is the organization of this sample:
- Prompt the user to input the server name, and his username/password (in case of SQL Server Authentication), or use Windows Authentication instead.
- Enumerate all the databases on that server.
- Whenever the the click any object from from the list of the supported objects in this sample, the object children (only those from the types supported in the list), will be displayed under this object.
So I believe that this is a very simple sample, and as I always believe, samples speak better than words, so I'll just put the link for this sample, and if any one interested to ask any question, feel free to post a comment on this article and I'll answer it as soon as I could.
You can download the sample from:
http://www.mmeshref.com/smo_server_sample.zip
Thank you so much.