Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
scabral7
Yak Posting Veteran
57 Posts |
Posted - 2010-06-05 : 23:23:51
|
Hi,i created an SMO Transfer Object Script in SSIS using script task and would like to script out the T-SQL of the transfer to see exactly what it will run when i actually transfer the object (view in this case). However, how to i send the output of the ScriptTransfer() method to a file or to a screen so that i can view it? here is my code: Dim dbSourceName As String = "SMSPHdreb0f0"Dim dbDestName As String = "SMSPHdreb0f0"'Connect to the local, default instance of SQL Server.Dim srvSource As ServersrvSource = New Server("dssdbs47")Dim srvTarget As ServersrvTarget = New Server("dssdbs108")'Reference the source databaseDim db As Databasedb = srvSource.Databases(dbSourceName)Dim dbCopy As DatabasedbCopy = srvTarget.Databases(dbDestName)'Define a Transfer object and set the required options.Dim xfr As Transferxfr = New Transfer(db)xfr.CopyAllTables = Falsexfr.CopyAllDefaults = Falsexfr.ObjectList.Add(db.Views("cd_desc_dcl", "dbo"))xfr.CopyAllStoredProcedures = Falsexfr.CopyAllDatabaseTriggers = Falsexfr.CopyAllObjects = Falsexfr.CopyAllPartitionFunctions = Falsexfr.CopyAllPartitionSchemes = Falsexfr.CopyAllRoles = Falsexfr.CopyAllRules = Falsexfr.CopyAllSchemas = Falsexfr.CopyAllSqlAssemblies = Falsexfr.CopyAllSynonyms = Falsexfr.CopyAllUserDefinedAggregates = Falsexfr.CopyAllUserDefinedDataTypes = Falsexfr.CopyAllUserDefinedFunctions = Falsexfr.CopyAllUserDefinedTypes = Falsexfr.CopyAllUsers = Falsexfr.CopyAllViews = Falsexfr.DropDestinationObjectsFirst = Truexfr.Options.WithDependencies = Falsexfr.Options.ContinueScriptingOnError = Falsexfr.Options.ClusteredIndexes = Falsexfr.Options.Indexes = Falsexfr.Options.DriAllKeys = Falsexfr.Options.DriForeignKeys = Falsexfr.Options.DriPrimaryKey = Falsexfr.Options.AllowSystemObjects = Falsexfr.Options.PrimaryObject = Falsexfr.Options.DriWithNoCheck = Falsexfr.Options.NonClusteredIndexes = Falsexfr.Options.OptimizerData = False'xfr.Options.IncludeIfNotExists = truexfr.DestinationDatabase = dbCopy.Namexfr.DestinationServer = srvTarget.Namexfr.DestinationLoginSecure = Truexfr.PrefetchObjects = Falsexfr.CopySchema = True'Include dataxfr.CopyData = True'Execute the transfer'xfr.TransferData()'Script the transferxfr.ScriptTransfer()Dts.TaskResult = ScriptResults.Success if i comment out the xfr.TransferData(), it migrates the view successfully to my destination server. However, i want to see the actual code it is running but i don't know how to send the data to a file using ScriptTransfer().thanksscott |
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2010-06-05 : 23:49:56
|
ScriptTransfer() returns a StringCollection. Just loop through the collection, dumping each element to your file. elsasoft.org |
|
|
scabral7
Yak Posting Veteran
57 Posts |
Posted - 2010-06-05 : 23:57:06
|
Thanks,i'm fairly new to vb.net. I can figure out the loop part, but how to i write the results to a file? |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2010-06-06 : 02:53:21
|
see this class: System.IO.StreamWriter elsasoft.org |
|
|
|
|
|