我们先简单的了解一下什么是消息队列(MSMQ)?消息队列是 Windows
2000(NT也有MSMQ,WIN95/98/me/xp不含消息队列服务但是支持客户端的运行)操作系统中通讯的基础,也是用于创建分布式、松散连接通讯应用程序的工具。这些应用程序可以通过不同种类的网络进行通讯,也可以与脱机的计算机通讯。消息队列分为用户创建队列和系统队列,用户队列分为:
public Sub client() Dim tM As New
System.Messaging.MessageQueue() tM.Path = ".\Private$\jk"
'"FORMATNAME:PUBLIC=3d3dc813-c555-4fd3-8ce0-79d5b45e0d75"'与指定计算机中的消息队列建立连接, Dim
newMessage As New
System.Messaging.Message(TextBox1.Text)'接受文本筐的t-sql语句 newMessage.Label
= "This is the label"'消息名字, tM.Send(newMessage)'发送消息 End
Sub
服务端程序:
public Sub server() Dim NewQueue As New
System.Messaging.MessageQueue(".\Private$\jk")'"FORMATNAME:PUBLIC=3d3dc813-c555-4fd3-8ce0-79d5b45e0d75"'与指定计算机中的消息队列建立连接, Dim
m As System.Messaging.Message '查看消息队列中的消息 m = NewQueue.Receive
m.Formatter = New System.Messaging.XmlMessageFormatter(New String()
{"System.String,mscorlib"}) Dim st As String st =
m.Body'消息队列中消息的消息内容。既sql语句 Dim con As New
OleDb.OleDbConnection("输入自己的数据库连接字符串") con.Open() Dim com As New
OleDb.OleDbCommand(st,
con)'执行消息中的sql语句 com.ExecuteNonQuery() con.Close() End
Sub