static
{
SqlConnection myConnection;
SqlCommand myCommand;
Messenger sender =
Console.WriteLine("Please enter the database name and key value");
inputArgs = Console.ReadLine();
}
databaseName = inpt.Substring(5,(inpt.Length-5));
keyValue = inpt.Substring(5,(inpt.Length-5));
sqlServer = inpt.Substring(5,(inpt.Length-5));
connectionString = "Data Source=" + sqlServer+";Integrated Security=SSPI;Initial Catalog=" + databaseName;
myConnection =
myCommand = myConnection.CreateCommand();
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "pro_TCP2MSG_PORT";
myCommand.Parameters.Add("@Keyvalue",SqlDbType.VarChar,10);
myCommand.Parameters.Add("@Port",SqlDbType.VarChar,10);
myCommand.Parameters.Add("@QueuePath",SqlDbType.VarChar,40);
myCommand.Parameters["@Keyvalue"].Value = keyValue;
myCommand.Parameters["@Port"].Direction = ParameterDirection.Output;
myCommand.Parameters["@QueuePath"].Direction = ParameterDirection.Output;
myConnection.Open();
port = Convert.ToInt32(myCommand.Parameters["@Port"].Value.ToString());
queuePath = myCommand.Parameters["@QueuePath"].Value.ToString();
Console.WriteLine("ERROR!! : " + sexp.Message.ToString()+ "Please check with your DBA regarding this error");
Console.WriteLine("The program will terminate in 10 seconds");
Thread.Sleep(10000);
Console.WriteLine("ERROR!! : No data was found for the input value " + keyValue.ToUpper() + " Please check with your DBA regarding this error");
myConnection.Close();
myCommand.Dispose();
myConnection.Dispose();
GC.Collect();
Socket server =
IPEndPoint myself =
server.Bind(myself);
server.Listen(5);
Socket client = server.Accept();
IPEndPoint newClient = (IPEndPoint)client.RemoteEndPoint;
Console.WriteLine("Connected with {0} at port# {1} on {2}",newClient.Address,newClient.Port,conTime);
data = sender.ReceiveVarData(client);
Console.WriteLine("Disconnected with {0} on {1}", newClient.Address,disTime.ToString());
client.Close();
client = server.Accept();
newClient = (IPEndPoint)client.RemoteEndPoint;
conTime = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();
sender.SendToQueue(data,queuePath);
sender.RecordMessage(data,queuePath);
Console.WriteLine("ERROR! Cannot receive data from the client...");
Console.WriteLine("DETAIL ERROR: " + sexp.Message.ToString());
Console.WriteLine("Disconnecting from client and waiting for a new client...");
data =
"Min Pool Size=1;Max Pool Size=5;Pooling=True";
recv = s.Receive(datasize,0,4,SocketFlags.None);
size = Convert.ToInt32(Encoding.ASCII.GetString(datasize));
recv = s.Receive(data,total,dataleft,SocketFlags.None);
total += recv;
dataleft -= recv;
Message queMsg =
Console.WriteLine("Sending message length " + tcpMsg.Length.ToString() + " to the queue " + queuePath);
MessageQueue newQueue = MessageQueue.Create(@".\Private$\"+queuePath);
newQueue.SetPermissions("Everyone",MessageQueueAccessRights.FullControl);
newQueue.Label = queuePath;
newQueue.Send(queMsg);
newQueue.Close();
newQueue.Dispose();
queMsg.Dispose();
MessageQueue existingQueue =
existingQueue.Send(queMsg);
existingQueue.Close();
existingQueue.Dispose();