从C#Win CE向SQL Server消息队列发送消息

时间:2013-02-01 12:49:53

标签: c# sql-server windows-ce message-queue

我在SQL Server ITSERVER上的数据库cja中有一个名为log_line_queue的队列。

我在移动设备上运行了一个C#Win CE应用程序。我想从此应用程序向log_line_queue发送消息。

到目前为止,这是我的代码:

var myQueue = new System.Messaging.MessageQueue("FormatName:Direct=OS:itserver\\private$\\dbo.cja.log_line_queue");

myQueue.Send("My Message Data.", MessageQueueTransactionType.Automatic);

导致

System.Messaging.MessageQueueException: Message Queue service is not available.
   at System.Messaging.MessageQueue.MQCacheableInfo.get_WriteHandle()
   at System.Messaging.MessageQueue.StaleSafeSendMessage(MQPROPS properties, IntPtr transaction)
   at System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransactionType transactionType)
   at System.Messaging.MessageQueue.Send(Object obj, MessageQueueTransactionType transactionType)
   at cjaTest1.MessageQueue.FrmSendToQueue.button1_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
   at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
   at Microsoft.AGL.Forms.EVL.EnterModalDialog(IntPtr hwnModal)
   at System.Windows.Forms.Form.ShowDialog()
   at cjaTest1.FrmMainForm.button9_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
   at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
   at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
   at System.Windows.Forms.Application.Run(Form fm)
   at cjaTest1.Program.Main()

我确信我做错了很多事。欢迎提出建议。

1 个答案:

答案 0 :(得分:1)

System.Messaging.MessageQueue用于与MSMQ进行互动。 A queue called log_line_queue in database cja on SQL Server ITSERVER是表或Service Broker队列。这是苹果和橘子,MSMQ与SQL Server无关。要将消息发送到SQL Server队列,必须使用SEND T-SQL谓词,并且必须连接到SQL Server实例。