Search code examples
sqlsql-server-2008smo

CopyAllViews = false is being ignored by SMO


I want SMO to not script the views so I do this

 var transfer = new Transfer(database)
    {
        CopyAllTables = true,
        CopyAllDefaults = false,
        CopyAllStoredProcedures = true,
        CopyAllDatabaseTriggers = true,
        CopyAllObjects = false,
        CopyAllPartitionFunctions = false,
        CopyAllPartitionSchemes = false,
        CopyAllRoles = false,
        CopyAllRules = true,
        CopyAllSchemas = true,
        CopyAllSqlAssemblies = false,
        CopyAllSynonyms = false,
        CopyAllUserDefinedAggregates = true,
        CopyAllUserDefinedDataTypes = true,
        CopyAllUserDefinedFunctions = true,
        CopyAllUserDefinedTypes = true,
        CopyAllUsers = false,
        CopyAllViews = false,
        Options =
        {
            WithDependencies = true,
            DriAll = true,
            Triggers = true,
            Indexes = true,
            SchemaQualifyForeignKeysReferences = true,
            ExtendedProperties = true,
            IncludeDatabaseRoleMemberships = false,
            Permissions = true,
            IncludeDatabaseContext = true
        },
        PreserveDbo = true,
    };

    transfer.ScriptTransfer()

but the views are still scripted.

I really want to be able to use transfer as it seems to be the only way to get the objects scripted in dependency order without writing more code. I set "CopyAllObjects = false" because I thought maybe that was causing the rest of the options that I had set to be ignored, but it didn't seem to do any good.

My goal here is to script out the views separately because I have a database server with views that depend on each other and will need to use dependencywalker on the views in all databases to script them in dependency order.

Please help?


Solution

  • I didn't exactly fix it but ended up filtering out any lines with "create view" in them. so I just call

     transfer.ScriptTransfer().Cast<string>().ToList()
    

    unless I am missing something, a lot of these flags (like CopyAllUsers) in the options SMO seems to only honor when it feels like it. :( it's a shame when some options looks exactly like what I need but do not work.