Reputation: 2826
I am writing a SMO script to export my SQL Server 2016 database to a text file. However the Scripter
always prepends this comment before my script:
/* ==Scripting Parameters==
Source Server Version : Version140 (14.0.600)
Source Database Engine Edition : Enterprise
Source Database Engine Type : Standalone
Target Server Version : Version140
Target Database Engine Edition : Enterprise
Target Database Engine Type : Standalone
*/
How can I disable the generation of this comment?
I tried setting IncludeHeaders
to false
/true
but this enables/disables another comment.
I use SMO like this:
var connectionString = "...";
var serverConnection = new ServerConnection(new SqlConnection(connectionString));
var sqlServer = new Smo.Server(serverConnection);
var createDbScriptOptions = new Smo.ScriptingOptions();
createDbScriptOptions.NoFileGroup = true;
createDbScriptOptions.IncludeFullTextCatalogRootPath = false;
StringCollection strcoll = db.Script(createDbScriptOptions);
foreach (String st in strcoll)
{
Console.WriteLine(st);
}
Or when scripting tables or other objects with
scripter.Script(new Urn[] { tb.Urn }
or
scripter.EnumScript(new Urn[] { tb.Urn }
the comment gets added as well.
Upvotes: 1
Views: 697
Reputation: 621
Apparently this is a new feature that comes with SSMS v17.2 and there's not yet a SMO scripting options flag to turn it off. Should be in the next release of SSMS.
See post on Microsoft Connect:
Posted by Microsoft on 8/29/2017 at 1:44 PM I'll be adding a new scripting option for producing the header in the next release of SMO/SSMS. This will be false for default which means you will not get the new header unless you specifically enable it. Thanks for the feedback! -Charles Gagnon ([email protected])
Upvotes: 3
Reputation: 2404
Have you tried...
createDbScriptOptions.IncludeDatabaseContext = false;
Upvotes: 0