jwcolby
jwcolby at colbyconsulting.com
Fri Nov 20 09:35:42 CST 2009
The object I am referring to is the SMO or SQL Server Management object. In order to use it you
have to add several references:
Microsoft.SQLServer.SMO
Microsoft.SQLServer.SMOEnum
Microsoft.SQLServer.SQLEnum
Microsoft.SQLServer.ConnectionInfo
then in the classes using the SMO you have to do
using Microsoft.SqlServer.Management.Smo;
After that you can do things like:
Server Svr;
Svr = new Server("MyServerName")
foreach (Database in Svr.Databases)
{
//Etc.
//
}
This allows you to iterate collections of database objects, using them directly or just pulling the
names out (as I did) to populate lists, combos, collections etc.
As I mentioned, once you have a database object you can manipulate it. I am just starting to learn
what I can do with this API but it looks pretty powerful.
John W. Colby
www.ColbyConsulting.com
jwcolby wrote:
> The blind leading the blind here.
>
> 1) I built a main application
> 2) I referenced the existing file repair applet from the main application (project).
> 3) I set a using statement. It appears that you have to both reference it and then use the "using"
> statement.
> 4) I can now open forms out in the file repair applet from the main application.
> 5) I physically moved the file repair applet underneath the main application directory.
> 6) I changed the directory for the applet and it just worked. That was fairly easy.
>
> From this point on I "Add Project" to the main solution. I have added a class project to wrap the
> DMO. In case you haven't discovered it, the DMO is a real cool SQL Server Management Object API
> that allows you to see and manage database objects. I am just getting into it but it allows me to
> reference a server object, then see the database collection. The each database object has a table
> collection, the table object has a fields collection etc. Everything you can see and manage in the
> SQL Server management studio you can (apparently) see and manage from the SMO from C#.
>
> An example of what this does for me is allows me to see all of the databases in a server, and thus
> populate a combo with their names. Selecting a database from the combo I can see and fill a combo
> with the names of the tables. Selecting a database and a specific table I can then can then run my
> stored procedures that export that table in that database to CSV files.
>
> That kind of stuff is what I do a lot of and what the big application will manage.
>
> John W. Colby
> www.ColbyConsulting.com