gpt4 book ai didi

c# - 从 SQL Server 2008 R2 使用 GSM 调制解调器发送 SMS

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:37 25 4
gpt4 key购买 nike

我想在 SQL Server 2008 中使用 GSM 调制解调器的 AT 命令发送 SMS,因此我编写了一个 Visual C# SQL CLR 数据库项目和一个存储过程。

但是当我执行那个存储过程时,我收到了这个错误:

Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

存储过程的源代码和发送短信的类是这些:

[Microsoft.SqlServer.Server.SqlProcedure]
public static void SendSMS2(string phone, string message)
{
SMSManagement.SM2S ss = new SMSManagement.SM2S();
ss.SendMessage(phone, message);
}

public void SendMessage(string PhoneNumber, string Message)
{
try
{
SerialPort port = new SerialPort();

port.PortName = "COM5";
port.BaudRate = 115200;
port.DataBits = 8;
port.StopBits = StopBits.One;
port.Parity = Parity.None;
port.ReadTimeout = 300;
port.WriteTimeout = 300;

// Error occurred in here.
port.Open();
port.DtrEnable = true;
port.RtsEnable = true;

SMS sms = new SMS();
sms.Direction = SMSDirection.Submited;
sms.PhoneNumber = PhoneNumber;
sms.ValidityPeriod = new TimeSpan(4, 0, 0, 0);
sms.Message = Message;

Message = sms.Compose(SMS.SMSEncoding.UCS2);

ExecCommand(port, "AT", 300, "No phone connected");
ExecCommand(port, "AT+CMGF=0", 300, "Failed to set pdu format.");
ExecCommand(port, "AT+CMGS=1", 300, "Failed to set message length.");
string command = Message + char.ConvertFromUtf32(26);
ExecCommand(port, command, 6000, "Failed to send message");

port.Close();
}
catch (Exception ex)
{
SqlContext.Pipe.Send(ex.Message);
}
}

Visual Studio和SQL Server的版本是2010 SP1和2008 R2。CLR项目框架为2.0。

最佳答案

您没有提到如何将程序集安装到 SQL Server 中。如果您只是直接从 Visual Studio 部署 - 您指定了什么权限级别??

enter image description here

默认值是 Safe,只要您只在 SQL Server 中工作——正则表达式匹配或类似的东西,这是可以的。

如果你想从 SQL Server“伸出手”并与世界沟通,你必须设置 Permission LevelUnsafe 之前您将程序集部署到 SQL Server 中。

关于c# - 从 SQL Server 2008 R2 使用 GSM 调制解调器发送 SMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8268723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com