views:

324

answers:

3

I'm currently using SMO and C# to traverse databases to create a tree of settings representing various aspects of the two databases, then comparing these trees to see where and how they are different.

The problem is, for 2 reasonably sized database, it takes almost 10mins to crawl them locally and collect table/column/stored procedure information I wish to compare.

Is there a better interface then SMO to access databases in such a fashion? I would like to not include any additional dependencies, but I'll take that pain for a 50% speed improvement. Below is a sample of how I'm enumerating tables and columns.

        Microsoft.SqlServer.Management.Smo.Database db = db_in;
        foreach (Table t in db.Tables)
        {
            if (t.IsSystemObject == false)
            {

                foreach (Column c in t.Columns)
                {
                }                    
            }
        }
+2  A: 

Use the system views in each database and query conventionally.

http://www.microsoft.com/downloads/details.aspx?familyid=2EC9E842-40BE-4321-9B56-92FD3860FB32&displaylang=en

Sam
+2  A: 

Try to force SMO to read all the required fields at once, instead of querying on access. See this blog for more information

devio
This has been a significant speed up without requiring drastic change in approach like the above option, thanks.
Scott Markwell
What used to take 10 mins now executes in ~40seconds
Scott Markwell
A: 

There is little that you can't get via TSQL queries. Getting metadata that way is usually very fast.

Anthony