everyone I have written simple Client - Server project. Client sends DataSet to Server and Server save data to SQLite DB. A used http://ift.tt/16rVB02 example. But server usage of RAM increase with time what causes a memoryexeception, although I send fixed size data from fixed number of client. Here is code sample.
public static void fillTable(SQLiteConnection connection, byte[] binaryData)
{
DataTable dt = DisSer(binaryData).Tables[0];
using (SQLiteCommand cmd = connection.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into 'LOG' (COMP,USER,SITE,DATE,DATA) values (@MachineName, @UserName, @LocationURL, @DateTime, @Data)";
cmd.Parameters.Add(new SQLiteParameter("@MachineName", DbType.String));
cmd.Parameters.Add(new SQLiteParameter("@UserName", DbType.String));
cmd.Parameters.Add(new SQLiteParameter("@LocationURL", DbType.String));
cmd.Parameters.Add(new SQLiteParameter("@DateTime", DbType.String));
cmd.Parameters.Add(new SQLiteParameter("@Data", DbType.String));
foreach (DataRow dr in dt.Rows)
{
cmd.Parameters["@MachineName"].Value = dr["COMP"].ToString();
cmd.Parameters["@UserName"].Value = dr["USER"].ToString();
cmd.Parameters["@LocationURL"].Value = dr["SITE"].ToString();
cmd.Parameters["@DateTime"].Value = dr["DATE"].ToString() + DateTime.Now.Millisecond.ToString();
cmd.Parameters["@Data"].Value = dr["DATA"].ToString();
cmd.ExecuteNonQuery();
}
}
}
static public void connectToDataBase(string dataSourse)
{
connectionString = "Data Source=" + dataSourse + ";Version=3;";
if (!File.Exists(dataSourse))
{
SQLiteConnection.CreateFile(dataSourse);
using (connection = new SQLiteConnection(connectionString))
{
connection.Open();
using (var cmd = connection.CreateCommand())
{
cmd.CommandText = "CREATE TABLE LOG (ID INTEGER PRIMARY KEY AUTOINCREMENT,COMP TEXT , USER TEXT, SITE TEXT, DATE TEXT, DATA TEXT)";
cmd.ExecuteNonQuery();
}
connection.Close();
}
}
connection = new SQLiteConnection("Data Source=" + dataSourse + ";Version=3;");
connection.Open();
}
public static int Main(String[] args)
{
connectToDataBase("C:\\log2\\db.sqlite");
StartListening();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire