使用SMO,我遇到了一個很大的性能問題:我腳本中的所有數據庫對象(函數,用戶,角色,表...)以及腳本除了表以外的所有數據庫對象少於2分鐘,但是當我啓用表腳本時需要2個小時? 所以,我使用加載所有表格屬性:使用SMO編寫腳本表,解決性能問題
serverSQL.SetDefaultInitFields(typeof(SMO.Table), true);
使SMO更高性能 但它似乎沒有任何效果。 這裏我的代碼:
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();
}
最後一個問題,因爲對我來說是使用SQL腳本,並直接創建表腳本但SSMS,我可以表腳本在幾分鐘內(SSMS腳本嚮導使用SMO或SQL。腳本?) 謝謝給我一個問題來解決它。
Does this [this](http://www.codeproject.com/Questions/186062/smo-table -script-generation-performance-problem)對你來說意味着什麼? –