August 16, 2017 at 4:16 pm
Hello,
while running this script, getting error -
Exception calling "ScriptTransfer" with "0" argument(s): "Script transfer failed. "
For any dB it is exactly working fine, but for few it fails.
$server2 = "servername"
$Database='DB_name'
$Filepath="C:\" + $Database + ".sql"
$Bool = Test-Path -Path $Filepath
IF($Bool -eq $True) {Remove-Item $Filepath}
set-psdebug -strict
$ErrorActionPreference = "stop"
$ms='Microsoft.SqlServer'
$v = [System.Reflection.Assembly]::LoadWithPartialName( "$ms.SMO")
if ((($v.FullName.Split(','))[1].Split('='))[1].Split('.')[0] -ne '9') {
[System.Reflection.Assembly]::LoadWithPartialName("$ms.SMOExtended") | out-null
}
$My="$ms.Management.Smo"
$s = new-object ("$My.Server") $server2
$transfer = new-object ("$My.Transfer") $db
$transfer.Options.ScriptBatchTerminator = $true
$transfer.Options.ToFileOnly = $true
$transfer.Options.Filename = "$FilePath";
$transfer.Options.DriPrimaryKey = $true;
$transfer.Options.DriForeignKeys = $true;
$transfer.Options.DriUniqueKeys = $true;
$transfer.Options.DriClustered = $true;
$transfer.Options.DriNonClustered = $true;
$transfer.Options.DriChecks = $true;
$transfer.Options.DriDefaults = $true;
$transfer.Options.Triggers = $true;
$transfer.Options.ClusteredIndexes = $true;
$transfer.Options.NonClusteredIndexes = $true;
$transfer.Options.Indexes = $true;
$transfer.Options.DriIndexes = $true;
$transfer.Options.DriAllKeys = $true;
$transfer.Options.DriAllConstraints = $true;
$transfer.Options.DriAll = $true;
$transfer.Options.IncludeDatabaseContext = $false;
$transfer.Options.Permissions = $false;
$transfer.ScriptTransfer();
....
...
Invoke-Command -ComputerName .. ... ...
But it is breaking to the scripttransfer() function
Thanks.
August 17, 2017 at 12:08 pm
Any advise?
Thanks.
August 17, 2017 at 3:16 pm
I identified that it is happening while exporting some of the stored procedure.
Can I use / rewrite the above script to pass at which place the script is breaking while the export to file is happening? please advise.
Thanks.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply