-3
我有下面的程序,它接收XML格式的套接字流並將它們插入到SQL數據庫中。我的問題如下: - 在調試模式下啓動程序時,所有xml流都成功插入到數據庫中。 - 當它正常啓動(無調試模式)時,程序會插入一個xml流並錯過另一個(所以如果我有20個流,只會插入10個流)。C#套接字監聽器(服務器)
這段代碼有什麼錯誤?
client = Listener.AcceptTcpClient();
netstream = client.GetStream();
Status = "Connected to a client\n";
byte[] bytes = new byte[client.ReceiveBufferSize + 1];
netstream.Read(bytes, 0, Convert.ToInt32(client.ReceiveBufferSize));
// Return the data received from the client
string clientdata = System.Text.Encoding.ASCII.GetString(bytes);
Status="Client sent: " + clientdata ;
StorePolicy(clientdata);
Query = clientdata;
Query = Query.Replace("\0", "");
StorePolicy(Query);
Status="Received Query: " + Query;
StorePolicy("Received Query: " + Query);
netstream.Close();
client.Close();
///////////////insert into database/////////
try
{
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand Cmd = new SqlCommand();
string[] words = Query.Split(new[] { "</RECORD>" }, StringSplitOptions.None);
StorePolicy(Query);
foreach (string word in words)
{
if (!string.IsNullOrEmpty(word))
{
record = word.Replace("'", "''") + "</RECORD>";
StorePolicy(record);
StrQuery = "INSERT INTO SMSListenner(XMLText) VALUES ('" + record.Replace("'", "''") + "')";
Cmd = new SqlCommand(StrQuery, conn);
conn.Open();
Cmd.ExecuteReader();
conn.Close();
StorePolicy(StrQuery);
}
}
}
[mcve]請。這是太多的代碼。開始刪除東西,直到最少量的代碼仍然存在問題。 –
@ rory.ap完成。請檢查。謝謝 –
代碼應該很好地格式化,幾乎「編譯就緒」,這不是它是什麼。請閱讀[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)並返回。 –