从 SQL Server 2008 R2 使用 GSM 调制解调器发送 SMS
我想使用 SQL Server 2008 中的 GSM 调制解调器的 AT 命令发送 SMS,因此我编写了一个 Visual C# SQL CLR 数据库项目和一个存储过程。
但是当我执行该存储过程时,我收到此错误:
请求类型许可 'System.Security.Permissions.SecurityPermission,mscorlib, 版本=2.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089' 失败。
存储过程和发送短信的类的源代码如下:
[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。
I want to send SMS using GSM modem's AT-Commands from SQL Server 2008, so I wrote a Visual C# SQL CLR Database Project and a stored procedure.
But when I execute that stored procedure I received this error:
Request for the permission of type
'System.Security.Permissions.SecurityPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.
The source codes of stored procedure and the class for sending sms are these:
[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);
}
}
The version of Visual Studio and SQL Server is 2010 SP1 and 2008 R2.
The CLR project framework is 2.0 .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有提到如何将程序集安装到 SQL Server 中。如果您直接从 Visual Studio 部署 - 您指定了什么权限级别?
默认值为
Safe
,只要您只工作就可以在 SQL Server 中 - 正则表达式匹配或类似的东西。如果您想从 SQL Server“伸出援手”并与世界交流,您必须在部署您的 SQL Server 之前将
权限级别
设置为不安全
汇编到 SQL Server 中。You didn't mention how you installed your assembly into SQL Server. If you just deployed straight from Visual Studio - what permission level did you specify??
The default value is
Safe
, which is okay as long as you only work within SQL Server - regex matching or things like that.If you want to "reach out" from SQL Server and communicate with the world, you must set the
Permission Level
toUnsafe
before you deploy your assembly into SQL Server.