I have create script which is automatically generated by Scripter.Script() method.
But if want to get rid of file paths included in the script. Which property is need to be set while using Scripter class to generate script ?
SQL Script:
CREATE DATABASE [ContactManager] ON PRIMARY
( NAME = N'ContactManager', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\ContactManager.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'ContactManager_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\ContactManager.ldf' , SIZE = 5184KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
but now I want to generate script without primary statement like below:
CREATE DATABASE [ContactManager] GO
ScriptingOptions.NoFileGroup should suppress the additional filegroup clauses.
More info here.
Also, it seems that simply calling db.Script() without the property enabled omits the filegroup anyways, so I am not positive this will work for you without seeing your code.
See my example below:
Microsoft.SqlServer.Management.Smo.Server srv = new Server(".");
Microsoft.SqlServer.Management.Smo.Database db = new Database(srv, "Yak");
System.Collections.Specialized.StringCollection statements = db.Script();
Console.WriteLine(statements);
ScriptingOptions so = new ScriptingOptions();
so.NoFileGroup = false;
foreach (string s in db.Script(so))
{
Console.WriteLine(s);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With