Skip to content

Commit

Permalink
Remove Trustworthy setting requirement and replace with a proper PreD…
Browse files Browse the repository at this point in the history
…eployment script
  • Loading branch information
EitanBlumin committed Feb 12, 2020
1 parent f3ca889 commit 547bbb1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ClrHttpRequest/ClrHttpRequest.sqlproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
<PermissionSet>UNSAFE</PermissionSet>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>ClrHttpRequest.snk</AssemblyOriginatorKeyFile>
<Trustworthy>True</Trustworthy>
<Trustworthy>False</Trustworthy>
<AssemblyOwner>dbo</AssemblyOwner>
<GenerateCreateScript>True</GenerateCreateScript>
<EnableFullTextSearch>False</EnableFullTextSearch>
<Recovery>SIMPLE</Recovery>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
Expand Down Expand Up @@ -76,4 +79,13 @@
<ItemGroup>
<None Include="ClrHttpRequest.snk" />
</ItemGroup>
<ItemGroup>
<SqlCmdVariable Include="PathToSignedDLL">
<DefaultValue>C:\ClrHttpRequest\ClrHttpRequest.dll</DefaultValue>
<Value>$(SqlCmdVar__1)</Value>
</SqlCmdVariable>
</ItemGroup>
<ItemGroup>
<PreDeploy Include="Script.PreDeployment.sql" />
</ItemGroup>
</Project>
34 changes: 34 additions & 0 deletions ClrHttpRequest/Script.PreDeployment.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Pre-Deployment Script Template
--------------------------------------------------------------------------------------
This file contains SQL statements that will be executed before the build script.
Use SQLCMD syntax to include a file in the pre-deployment script.
Example: :r .\myfile.sql
Use SQLCMD syntax to reference a variable in the pre-deployment script.
Example: :setvar TableName MyTable
SELECT * FROM [$(TableName)]
--------------------------------------------------------------------------------------
*/

use [master];
GO
-- Make sure CLR is enabled in the instance
IF (SELECT value_in_use FROM sys.configurations WHERE name = 'clr enabled') = 0
BEGIN
PRINT N'Enabling CLR...'
EXEC sp_configure 'clr enabled', 1;
RECONFIGURE;
END
GO
IF NOT EXISTS (select * from sys.asymmetric_keys WHERE name = 'clr_http_request_pkey')
create asymmetric key clr_http_request_pkey
from executable file = '$(PathToSignedDLL)'
GO
IF NOT EXISTS (select name from sys.syslogins where name = 'clr_http_request_login')
create login clr_http_request_login from asymmetric key clr_http_request_pkey;
GO
grant unsafe assembly to clr_http_request_login;
GO
-- Return execution context to intended target database
USE [$(DatabaseName)];
GO

0 comments on commit 547bbb1

Please sign in to comment.