スクリプトを変数にロードするコードがあり、その変数をSMO オブジェクトに渡します。次の例外が発生します。
"1" 個の引数を指定して "ExecuteWithResults" を呼び出し中に例外が発生しました: "データベース 'Russell_Test' の結果での実行に失敗しました。"
- $serverName はサーバー名です。
- $databaseName はデータベース名です。
- $createScript は読み取られたスクリプトです。
この問題を解決するにはどうすればよいですか?
以下は、コードの関連部分です。
# Load Smo and referenced assemblies.
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.ConnectionInfo');
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.Management.Sdk.Sfc');
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO');
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMOExtended');
Try{
$server = New-Object Microsoft.SqlServer.Management.Smo.Server $serverName;
$db = $server.Databases.Item($databaseName);
$result = $db.ExecuteWithResults($createScript);
$result | Out-File -Append -FilePath $outputFile;
}
Catch
{
[system.exception]
$_.Exception | Out-File -Append -FilePath $outputFile
}