我想從SQL Server 2008使用GSM調制解調器的AT命令發送短信,所以我寫了一個Visual C#SQL CLR數據庫項目和一個存儲過程。從SQL Server 2008 R2發送帶GSM調制解調器的SMS
但是,當我執行該存儲過程,我收到此錯誤:
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。
你是如何將CLR程序集安裝到SQL Server中的?你使用了什麼命令和什麼設置? –
我將它部署到SQL Server中的我的數據庫中,並將它顯示在「程序集」列表中。 – ABI
是的 - 當然 - 但是**如何部署它?直接從Visual Studio ??然後查看我的答案並檢查您的設置。或者你用T-SQL腳本部署它('CREATE ASSEMBLY ......') - 然後請向我們展示該腳本! –