C# で記述された clr ストアド プロシージャに大きな問題があります。アセンブリを正常にインストールしましたが、ストアド プロシージャを呼び出すと、次のエラーが発生します。
Msg 6522, Level 16, State 1, Procedure RestoreDatabaseClr, Line 0
A .NET Framework error occurred during execution of user-defined routine or aggregate "RestoreDatabaseClr":
System.Exception: This functionality is disabled in the SQLCLR. It is recommended that you execute from your client application.
System.Exception:
at Microsoft.SqlServer.Management.Common.ConnectionManager..ctor()
at Microsoft.SqlServer.Management.Common.ServerConnection..ctor()
at Microsoft.SqlServer.Management.Smo.ExecutionManager..ctor(String name)
at Microsoft.SqlServer.Management.Smo.Server..ctor()
at DBRestoreClr.StoredProcedures.RestoreDatabaseClr(String backupFile, String dbName, String dataFiles, String logFiles)
.
これは、sproc で実行しようとしている C# コードです:-
using System;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Server;
namespace DBRestoreClr
{
public partial class StoredProcedures
{
[SqlProcedure()]
public static int RestoreDatabaseClr(string backupFile, string dbName, string dataFiles, string logFiles)
{
var sqlServer = new Server();
}
}
}
私は以下を使用して実行しています
EXEC @ReturnValue RestoreDatabaseClr 'C:\Workspace\DEV\DBRestoreDatabase\tests\Clr\restore.bak',
'restore',
'C:\2008\MSSQL10.MSSQLSERVER\MSSQL\DATA\restore',
'C:\2008\MSSQL10.MSSQLSERVER\MSSQL\DATA\restore\logs';
なぜそれが機能しないのか、誰にもアイデアがありますか?
ありがとう
アンドリュー