-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLR_SendSMS.sql
More file actions
60 lines (50 loc) · 1.91 KB
/
CLR_SendSMS.sql
File metadata and controls
60 lines (50 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-- Enable CLR on the database
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO
-- Set the datbase to trustworthy to resolve issues with security restrictions for the CLR, ensure you change the database name 'Demo' to your database instance
ALTER DATABASE Demo SET TRUSTWORTHY ON
-- Register assemblies to allow the code to run
IF NOT EXISTS (SELECT name FROM sys.assemblies WHERE name = 'System_Runtime_Serialization')
BEGIN
CREATE ASSEMBLY System_Runtime_Serialization FROM 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.Serialization.dll'
WITH PERMISSION_SET = UNSAFE
END
GO
IF NOT EXISTS (SELECT name FROM sys.assemblies WHERE name = 'System_Web')
BEGIN
CREATE ASSEMBLY System_Web FROM 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Web.dll'
WITH PERMISSION_SET = UNSAFE
END
GO
IF NOT EXISTS (SELECT name FROM sys.assemblies WHERE name = 'Microsoft_CSharp')
BEGIN
CREATE ASSEMBLY Microsoft_CSharp FROM 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.CSharp.dll'
WITH PERMISSION_SET = UNSAFE
END
GO
IF EXISTS (SELECT name FROM sys.assemblies WHERE name = 'comapiOneApi')
drop assembly comapiOneApi
-- Note: Update the file path below to point to the compiled comapi-quickstart-sql-clr-integration.dll file on your server.
CREATE ASSEMBLY comapiOneApi from 'D:\Work\GitHub\comapi-quickstart-sql-clr-integration\comapi-quickstart-sql-clr-integration\bin\Debug\comapi-quickstart-sql-clr-integration.dll'
WITH PERMISSION_SET = UNSAFE
GO
SELECT * FROM sys.assemblies
GO
-- Create a stored proc linked to the comapiOneApi CLR assembly we just registered
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'SendSMS')
drop procedure SendSMS
GO
CREATE PROCEDURE SendSMS
(
@phoneNumber NVARCHAR(20),
@from NVARCHAR(20),
@message NVARCHAR(4000) )
AS
EXTERNAL NAME comapiOneApi.ComapiOneApi.Send
GO