我用 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';
任何人有任何想法为什么它不工作?
谢谢
安德鲁