Skip to content

SMO objects can't be scripted when IsDesignMode == true #27

@shueybubbles

Description

@shueybubbles

Over the years, "design mode" has been neglected such that SMO requires a live connection to a server in order to construct an object hierarchy and generate scripts for it.

EG this throws an exception during Script():

            // setting ServerVersion allows setting Database.Parent without a server query to get the version
            // set TrueName to ensure the URN that identifies the Server is complete
            var serverConnection = new ServerConnection() { ServerVersion = new ServerVersion(15, 0), TrueName = "designMode" };
            var server = new Management.Smo.Server(serverConnection);
            // designmode requires an offline connection
            (server as ISfcHasConnection).ConnectionContext.Mode = SfcConnectionContextMode.Offline;
            var database = new Database()
            {
                Parent = server,
                Name = "dbname"
            };
            var script = database.Script();

it should output CREATE DATABASE [dbname]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions