Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8445283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:37:06+00:00 2026-06-10T09:37:06+00:00

With SMO, I meet a big performance problem : I script all Database object

  • 0

With SMO, I meet a big performance problem : I script all Database object (functions, users, roles, table…) and when I script all Database object except table, it take less than 2 minutes, but when i enable table scripting it take 2 hours?
So, i load all table properties using:

   serverSQL.SetDefaultInitFields(typeof(SMO.Table), true);

to make SMO more performant
but it seems to have no effect.
here my code :

public static string dumpTables(SMO.TableCollection tables)
        {
            int cpt = 0;
            SMO.ScriptingOptions scriptingOptions = new SMO.ScriptingOptions();
            StringBuilder sb = new StringBuilder();
            scriptingOptions.IncludeIfNotExists = true;
            scriptingOptions.DriAll = true;
            scriptingOptions.ExtendedProperties = true;  

            foreach (SMO.Table table in tables)
            {
                sb.Append("-- Table " + table.Name + "\n");

                foreach (string scriptline in table.Script(scriptingOptions)) //Script call take a long time
                {
                    sb.Append(scriptline + Environment.NewLine );
                }
                sb.Append("GO" + Environment.NewLine);
                cpt++;
                Console.WriteLine(string.Format("Table {0} : {1}", cpt.ToString(), table.ToString()));
            }
            return sb.ToString();
        }

the last issue, as for me is to use sql script and directly create table script but with SSMS, I can make table script in few minutes.(SSMS Script wizard use SMO or sql script?)
Thank to give me an issue to fix it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:37:07+00:00Added an answer on June 10, 2026 at 9:37 am

    I find many workaround:
    After logging all script one by one for each SMO.Table, I discover that some script take less than 1 second, other take about 50 second!

    1. So a first workaround is to work with multithreading.Doing so, make my scripting that took 2 hours to take know only 20 minutes 600% faster. I try with a basic ThreadPool, without optimize it in testing how many thread allow the best performance. I will say you it after. (I will test using different number of thread and logged it in order to see the number of thread in my computer that improve best performance)

    2. Another workaround, is to use DBDiff in codeplex which source allow you to script faster without SMO but not usefull for those who want less code (script manually ;-). You have to use class to create sql script.But the tool is very good to synchronise database;-)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script for restoring a database with PowerShell and SMO. Now I
I am using SMO to script out my objects from Sql server database using
I'm trying to create a table using SMO, and further use the SqlBulkCopy object
I have SMO code which copies tables from one database to another. It runs
I want to create a server smo object in my function, then use it
I'm enumerating all databases of an SQL Server 2005 instance using SMO like as
I am using the Microsoft.SqlServer.Management.Smo classes to script out SQL scripts for stored procedures,
I have a class that creates the object of type Smo. The object then
Is it possible to run a script using Microsoft.SqlServer.Management.Smo? I am able to generate
Using the Microsoft.SqlServer.Management.Smo.Scripter object, I'm generating scripts for each of the tables in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.