我正在SQL Server 2017中创建CLR存储过程。在以前的版本中,我已经做了很多次,没有任何问题;但是,我们最近更新到了SQL Server 2017。
我知道此升级带来的安全性问题,但是我想确保在开始破坏安全性之前可以部署CLR。我创建了一个名为Test
的数据库,并将Trustworthy
设置为ON(不好,我知道这是临时的)。我不断收到以下错误:
在程序集“ Get_API_Data”中找不到类型“ CLR_Get_API_Data.StoredProcedures”。
我发现了几篇文章,例如:SQL Server: Could not find type in the assembly,该文章处理了此错误,但是他们将代码构建在一个类中,而不是类型为
storedProcedures
的部分类中。
这是我创建存储过程的SQL脚本:
USE Test GO --Alter Database Test --Set Trustworthy on --EXEC sp_configure 'clr strict security', 1; --RECONFIGURE; IF EXISTS (SELECT * FROM sys.assemblies asms WHERE asms.name = N'Get_API_Data' AND is_user_defined = 1) DROP ASSEMBLY [Get_API_Data] GO CREATE ASSEMBLY Get_API_Data FROM 'C:\Users\Administrator\Documents\Visual Studio 2015\Projects\CLR_Assemblies\Get_API_Data\Get_API_Data\bin\Debug\Get_API_Data.dll' WITH Permission_Set = Safe --EXTERNAL_ACCESS GO --Assembly Name,[SolutionName.StoredProcedures].Sub Name CREATE PROCEDURE [dbo].[GetAPI] AS EXTERNAL NAME Get_API_Data.[CLR_Get_AMS_API_Data.StoredProcedures].GetAPI GO
我的解决方案名称为
CLR_Get_API_Data
,项目名称为Get_API_Data
,方法名称为GetAPI
。以下是我的Visual Studio代码:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Net;
using System.IO;
public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void GetAPI ()
{
// Stuff happens here
} //Ends Public Void Get
} //Ends Class
我正在SQL Server 2017中创建CLR存储过程。在以前的版本中,我已经做了很多次,没有任何问题;但是,我们最近更新到了SQL Server2017。我知道...
使用局部类没有错。