传输对象默认值不传输

时间:2014-04-09 21:21:58

标签: sql sql-server data-transfer-objects

我正在尝试使用Transfer Class将数据库从一台服务器复制到另一台服务器。我无法成功传输列默认值。其他一切(数据,约束等)都没有问题。从备份恢复不是一种选择。

try{Import-Module SQLPS -DisableNameChecking}
catch{write-error "Could not import SQLPS powershell module."}

$SourceInstanceName = 'localhost'
$DestInstanceName = xxx'
$CopyDBName = 'xxx'
$SourceDBName = 'xxx'


$source  = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $SourceInstanceName

$mySrvConn = new-object Microsoft.SqlServer.Management.Common.ServerConnection
$mySrvConn.ServerInstance=$DestInstanceName
$mySrvConn.LoginSecure = $false
$mySrvConn.Login = "xxx"
$mySrvConn.Password = "xxx"


$dest =  New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server($mySrvConn)
#create SMO handle to your database
$SourceDB = $source.Databases[$SourceDBName]

#database to hold the copy of your source database
$CopyDB = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Database -ArgumentList $dest , $CopyDBName
$CopyDB.Create()

#Use SMO Transfer Class by specifying source database
#you can specify properties you want either brought over or excluded, when the copy happens
$ObjTransfer = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Transfer -ArgumentList $SourceDB

$ObjTransfer.DestinationDatabase = $CopyDBName
$ObjTransfer.DestinationServer = $DestInstanceName
$ObjTransfer.DestinationLoginSecure = $false # can enable once all servers are on domain
$ObjTransfer.DestinationLogin = 'xxxxxx'
$ObjTransfer.DestinationPassword = 'xxxxxx' 

#if you wish to just generate the copy script
#just script out the transfer
 #$ObjTransfer.ScriptTransfer()

#When you are ready to bring the data and schema over,
#you can use the TransferData method


$ObjTransfer.CopyAllDatabaseTriggers = $true
$ObjTransfer.CopyAllDefaults = $true
$ObjTransfer.CopyAllFullTextCatalogs = $true
$ObjTransfer.CopyAllFullTextStopLists = $true

$ObjTransfer.CopyAllObjects = $true
$ObjTransfer.CopyAllPartitionFunctions = $true
$ObjTransfer.CopyAllPartitionSchemes = $true
$ObjTransfer.CopyAllPlanGuides = $true
$ObjTransfer.CopyAllRoles = $true
$ObjTransfer.CopyAllRules = $true
$ObjTransfer.CopyAllSchemas = $true
$ObjTransfer.CopyAllSearchPropertyLists = $true
$ObjTransfer.CopyAllSequences = $true
$ObjTransfer.CopyAllSqlAssemblies = $true
$ObjTransfer.CopyAllStoredProcedures = $true
$ObjTransfer.CopyAllSynonyms = $true
$ObjTransfer.CopyAllTables = $true
$ObjTransfer.CopyAllUserDefinedAggregates = $true
$ObjTransfer.CopyAllUserDefinedDataTypes = $true
$ObjTransfer.CopyAllUserDefinedFunctions = $true
$ObjTransfer.CopyAllUserDefinedTableTypes = $true
$ObjTransfer.CopyAllUserDefinedTypes = $true
$ObjTransfer.CopyAllViews = $true
$ObjTransfer.CopyAllXmlSchemaCollections = $true
$ObjTransfer.CopyData = $true
$ObjTransfer.CopySchema = $true
$ObjTransfer.DestinationTranslateChar = $true
$ObjTransfer.DropDestinationObjectsFirst = $true
$ObjTransfer.PrefetchObjects = $true
$ObjTransfer.PreserveDbo = $true
$ObjTransfer.PreserveLogins = $true
$ObjTransfer.SourceTranslateChar = $true
$ObjTransfer.UseDestinationTransaction = $true
$ObjTransfer.Options.WithDependencies = $true
$ObjTransfer.Options.ContinueScriptingOnError = $true

$ObjTransfer.TransferData()

1 个答案:

答案 0 :(得分:1)

找到我失踪的财产

xfrObject.Options.DriDefaults=True