[英]Create an Asymmetric key in a Visual Studio 2012 Sql Server project
I'm developing a Visual Studio 2012 SQL Server project with four CLR stored procedures. 我正在开发带有四个CLR存储过程的Visual Studio 2012 SQL Server项目。 I'm going to use it on a SQL Server 2012 server.
我将在SQL Server 2012服务器上使用它。
Before that project I have another one, only with the CLR Stored Procedure, and I use this sql to add it to my database: 在该项目之前,我还有另一个项目,仅使用CLR存储过程,并且使用此sql将其添加到我的数据库中:
-- #####################################################################
-- Add SQL CLR Procedures.
-- #####################################################################
Use master
go
-- Configure CLR execution on SQL Server.
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO
-- For stored procedure dll...
CREATE ASYMMETRIC KEY CodeServerAK FROM EXECUTABLE FILE = 'D:\MyPath\bin\Release\CodeServerDB.dll'
CREATE LOGIN SQLCLRCodeServerSP FROM ASYMMETRIC KEY CodeServerAK
GRANT EXTERNAL ACCESS ASSEMBLY TO SQLCLRCodeServerSP
go
USE MyDB
GO
-- Create users from assemblies' login name.
CREATE USER SQLCLRCodeServerSPUser FOR LOGIN SQLCLRCodeServerSP
GO
USE MyDB
GO
CREATE ASSEMBLY CodeServerDB FROM 'D:\MyPath\bin\Release\CodeServerDB.dll'
WITH PERMISSION_SET=EXTERNAL_ACCESS
GO
But now I have a problem: I don't know how to create the Asymmetric key CodeServerAK
because now I don't have the path to the dll. 但是现在我遇到了一个问题:我不知道如何创建非对称密钥
CodeServerAK
因为现在我没有dll的路径。
How can I create the asymmetric key? 如何创建非对称密钥?
I think I don't need to use this sql: 我想我不需要使用此sql:
CREATE ASSEMBLY CodeServerDB FROM 'D:\MyPath\bin\Release\CodeServerDB.dll'
WITH PERMISSION_SET=EXTERNAL_ACCESS
GO
I have publish the VS project on SQL Server and the assembly is there. 我已经在SQL Server上发布了VS项目,并且程序集在那里。
By the way, the assembly is signed. 顺便说一句,该程序集已签名。
As an inelegant solution I have a pre build step which copies the key file from a path relative to the project to a network share which is accessible by both the build machine and the target sql server eg copy /Y "$(ProjectDir)bin\\Release\\CodeServerDB.dll" "\\myserver\\share\\path" . 作为一种出色的解决方案,我有一个预构建步骤,该步骤将密钥文件从相对于项目的路径复制到网络共享,构建机器和目标sql服务器均可访问该网络共享,例如, 复制/ Y“ $(ProjectDir)bin \\ Release \\ CodeServerDB.dll“” \\ myserver \\ share \\ path“ 。
You can then update the CREATE ASYMMETRIC KEY command to reference the networked share. 然后,您可以更新CREATE ASYMMETRIC KEY命令以引用网络共享。
I haven't discovered yet how to have Visual Studio build and deploy the asymmetric key for automatically. 我还没有发现如何使Visual Studio自动生成和部署非对称密钥。
SideNote: You can have Visual Studio build and deploy the assembly for you without need to refer to the binary dll - check the Generate DDL option on the Project Settings SQLCLR tab, the CREATE ASSEMBLY statement is generated with encoded binary 注意:您可以使Visual Studio为您构建和部署程序集,而无需引用二进制dll-检查“项目设置” SQLCLR选项卡上的“ 生成DDL ”选项,CREATE ASSEMBLY语句是使用编码的二进制文件生成的
CREATE ASSEMBLY [My.SQLServer.SQLCLR]
AUTHORIZATION [dbo]
FROM 0x4D5A900003{...}0000000000000
WITH PERMISSION_SET = EXTERNAL_ACCESS;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.