[dba-VB] SMO was Projects vs Solutions

jwcolby jwcolby at colbyconsulting.com
Sat Nov 21 11:05:43 CST 2009


Shamil,

As far as I can tell they are quite different things, and perform different jobs.  I do use 
SQLClient.  SQLClient appears to be about getting at data, and I do use that for the ADO side of 
things.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.aspx

SMO appears to be about getting at and manipulating the objects in the database.

http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.aspx

SMO appears to be similar to the DAO object where you can see and manipulate the table (not the data 
IN the table) the fields, indexes and so forth.  It is a collection based object where you can drill 
down into a server and see the objects underneath the database, then (for example) drill down into a 
table and see the objects under the table.

Just as an example, using SMO in a few lines of code I got a list of all of the databases in the 
database collection of my server.  I used that to populate a database combo box.  When I select the 
database that I want to export data from, I then use SMO (again a couple of more lines of code) to 
get a list of the tables in the selected database and use that to populate a combo of tables.

I have no idea the relative merit of one way vs the other.  To me it is just a tool.  In this 
particular case I use it to quickly and easily get at the names of objects in the database.  I 
understand that using SMO you can do other maintenance kinds of things as well.  One of the things I 
have to do is copy an "order template" database to a new name in preparing to fill an order.  SMO 
appears to have built-in methods for doing this programmatically from C# - as opposed to running 
TSQL or using some other method.

Understand I am not an expert on any of this, in fact quite the opposite.  I stumbled across SMO and 
saw an example of how easy it was to get at the database STRUCTURE information and decided to use it 
for that purpose, when I had that need.  Is there another way to do this?  Almost certainly, given 
that there is always a dozen ways to do anything in programming.

Given your persistent questioning of my motives I guess now I have to ask whether I am causing 
myself problems doing this?

John W. Colby
www.ColbyConsulting.com


Shamil Salakhetdinov wrote:
> Hi John --
> 
> OK, but why not just use connections strings and System.Data.SqlClient
> classes, .... ?
> 
> Thank you.




More information about the dba-VB mailing list