Av rating:
Total votes: 11
Total comments: 16


Phil Factor
More Database Administration and Development Automation using DMO
04 October 2006

The Automating Common SQL Server Tasks using DMO article describes the sort of tasks that can be automated using SQL Server Distributed Management Objects (DMO), and provides practical examples of how to automate tasks such as enumerating all database on a given server, or creating a database on any given server.

This article extends further your automation toolkit, providing the following procedures:

  • spDBTransfer
    • Copy an entire database within a server or between servers
    • Copy selected tables or stored procedures between databases
  • spScriptObjects
    • Write out a complete build script for a database
    • Write out build scripts for every database on a server
    • Write out a series of source files for the objects in a database in a suitable format for source-control systems
  • spDatabaseRoles
    • List the database roles and the users assigned to them, for a particular database
  • spJobHistory
    • Check the jobs on a server for their success or otherwise and access the history records

Each of these procedures is designed to work either with SQL Server or Windows authentication. To download each of these procedures – which are fully commented and with example execution commands – simply, click the "Code Download" link in the box to the right of the article title.



This article has been viewed 7630 times.
Phil Factor

Author profile: Phil Factor

Phil Factor (real name withheld to protect the guilty), aka Database Mole, has 20 years of experience with database-intensive applications. Despite having once been shouted at by a furious Bill Gates at an exhibition in the early 1980s, he has remained resolutely anonymous throughout his career.

Search for other articles by Phil Factor

Rate this article:   Avg rating: from a total of 11 votes.


Poor

OK

Good

Great

Must read
 
Have Your Say
Do you have an opinion on this article? Then add your comment below:
You must be logged in to post to this forum

Click here to log in.


Subject: Where is the code?
Posted by: WilliamGrene (view profile)
Posted on: Monday, November 27, 2006 at 5:30 PM
Message: Where is the code then. I clicked on everything I could think of

Subject: re: Where is the code
Posted by: WilliamGrene (view profile)
Posted on: Monday, November 27, 2006 at 5:33 PM
Message: I can't believe I wrote that! I've now clicked on the code Download link up at the top of the article, just below the stars. Sorry!

Subject: Re: Where is the code
Posted by: Phil Factor (view profile)
Posted on: Monday, November 27, 2006 at 5:50 PM
Message: Yeah, caught me out too once. It's up there in what looks like a speech box. I hope you like the code. I'm quite proud of the code that gets the job history. It didn't come without a struggle.

Subject: SMO - scripting Server and Databases
Posted by: mg1 (view profile)
Posted on: Tuesday, November 28, 2006 at 6:59 AM
Message: Your article asked for SMO information. I've written a console app in VB.Net that will essentially re-create a server and user databases. We use as part of our DR process but obviously, it can be modified for other purposes.
If you would like the code, let me know how you would like me to send it to you. Keep in mind, I am NOT a VB programmer so it will look a bit "rough" but it gets the job done.

Subject: Re Scripting server and databases
Posted by: Phil Factor (view profile)
Posted on: Wednesday, November 29, 2006 at 4:25 AM
Message: We are very pleased to have contributions, and yours sounds very interesting. Please send them via Email to the editor, and he will pass them on. All DMO code looks rough, whatever one uses. If something works well in day to day use, then it will be of great benefit to others. Maybe we ought to start a DMO/SMO forum....

Subject: Running spDBTransfer with Windows Authentication
Posted by: Jon C (view profile)
Posted on: Friday, December 22, 2006 at 12:06 PM
Message: The comments in spDBTransfer say to replace user id and password with default if running under Windows Authentication. I'm not sure how to do that. What is the exact syntax?

Subject: Running spDBTransfer to transfer tables with criteria.
Posted by: imtiaz ul hoda (view profile)
Posted on: Wednesday, January 03, 2007 at 12:51 AM
Message: I run the spDBTransfer utility to copy tables between database. I need to define a criteria for my data not the complete table. is there any way out ?

Subject: Running spDBTransfer to transfer tables with criteria.
Posted by: Phil Factor (view profile)
Posted on: Wednesday, January 03, 2007 at 3:11 AM
Message: I'm sorry, but, at a quick glance, I can't see any way of doing it using DMO. Does anyone else have an idea?

Subject: Running spDBTransfer with Windows Authentication
Posted by: Phil Factor (view profile)
Posted on: Wednesday, January 03, 2007 at 3:12 AM
Message: the keyword DEFAULT should do the trick.

Subject: studying
Posted by: kimmy (not signed in)
Posted on: Tuesday, June 26, 2007 at 6:13 AM
Message: What does database administration means???? im a first yr. student!!!!!!!! Please help me!!!!!!!!

Subject: again
Posted by: kimmy (not signed in)
Posted on: Tuesday, June 26, 2007 at 6:17 AM
Message: And by the way... What does it do????
Help me please!!

Subject: Database Administration Automation
Posted by: Arturo (view profile)
Posted on: Friday, July 06, 2007 at 5:30 AM
Message: I need to be able to offer our users a simple method of detaching and attaching a database, without having to teach them how to use enterprise Manager. Do any scripts already exist, or is it relatively easy to create them ?

Subject: hi
Posted by: gigi (not signed in)
Posted on: Wednesday, October 10, 2007 at 12:44 PM
Message: im confused!!!

Subject: Keep an OLE Automation object running all day
Posted by: Anonymous (not signed in)
Posted on: Tuesday, November 20, 2007 at 10:36 AM
Message: Some of this code is very interesting. I noticed that each TSQL has to start out by doing sp_OACreate. Is it possible to instantiate the DLL once and let it run essentially permanently?

You could try to set up a polling situation with "waitfor delay", which would restart the DLL if it wasn't running. You'd have to save the objid in a table somewhere so that the new batches could reference it. But this doesn't see right.

Ideas?

Subject: Keep an OLE Automation object running all day
Posted by: Anonymous (not signed in)
Posted on: Tuesday, November 20, 2007 at 10:59 AM
Message: Some of this code is very interesting. I noticed that each TSQL has to start out by doing sp_OACreate. Is it possible to instantiate the DLL once and let it run essentially permanently?

You could try to set up a polling situation with "waitfor delay", which would restart the DLL if it wasn't running. You'd have to save the objid in a table somewhere so that the new batches could reference it. But this doesn't see right.

Ideas?

Subject: DMO to RMO
Posted by: Prishani (not signed in)
Posted on: Friday, July 18, 2008 at 11:19 AM
Message: Please help me out with this any one .I need to write a script in Vb code and we are using SQL SERVER 2005

 









Phil Factor
Bunnikins!
 When an IT manager is selected as a victim of office politics of a large corporate, it is time for him to engage in... Read more...



 View the blog
Using Powershell to Generate Table-Creation Scripts
 For all of us who learn best by trying out examples, Bob Sheldon produces a PowerShell script file for... Read more...

SQL Toolbelt 2008: Predominantly an Engineering Task
 The conversion of the Red-Gate tools to be compatible with SQL Server 2008 might not seem, on first... Read more...

Audit Crosschecks
 In this short article, the second of a 2-part series, William suggests a solution, using SQL Data... Read more...

XML Jumpstart Workbench
 In which Robyn and Phil decide that the best way of starting to learn XML is to jump in and take a ride... Read more...

Discovering Security Uses for SQL Compare
 Much of the security of SQL Server is implemented as part of the database schema. This provides some... Read more...

Beginning SQL Server 2005 Reporting Services Part 1
 Steve Joubert begins an in-depth tour of SQL Server 2005 Reporting Services with a step-by-step guide... Read more...

Ten Common Database Design Mistakes
 Database design and implementation is the cornerstone of any data centric project (read 99.9% of... Read more...

SQL Server Full Text Search Language Features
 SQL Full-text Search (SQL FTS) is an optional component of SQL Server 7 and later, which allows fast... Read more...

Beginning SQL Server 2005 Reporting Services Part 2
 Continuing his in-depth tour of SQL Server 2005 Reporting Services, Steve Joubert demonstrates the most... Read more...

Executing SSIS Packages
 Nigel Rivett demonstrates how to execute all SSIS packages in a given folder using either an SSIS... Read more...

Over 150,000 Microsoft professionals subscribe to the Simple-Talk technical journal. Join today, it's fast, simple, free and secure.

Join Simple Talk