I want to insert the data in database received from WebSocket but I'm getting a delay while inserting.
I'm using WebSocketSharp()
for WebSocket
the data I'm getting in JSON Format.
The hit count of WebS.OnMessage +=(s1,e1)=>
method in 550 times in 1 sec and the data received form websocket is single line getting single lines 500 in 1 sec and that need to be insert less then a 1sec or in millisecond.
data Sample->
{"seg":"BSE","currc":"0.012","code":"538610","ltt":"1683171716"}
WebSocket WebS =new WebSocket("SocketLinkHere");
WebS.OnOpen+=(s1,e1)=>
{
//no need
};
WebS.OnError +=(s1,e1)=>
{
if(!WebS.IsAlive)
{
WebS.close();
WebS.Connect();
}
};
WebS.OnClose +=(s1,e1)=>
{
//errorlist here
};
WebS.OnMessage +=(s1,e1)=>
{
try
{
string result="["+e1.Data+"]";
SQLEXE(result);//call method to insert result into database
}
catch(exception ex){}
};
WebS.Connect();
private void SQLEXE(string result)
{
try
{
DataTable dt=JsonConvert.DeserializeObject<DataTable>(result);
SqlParameter[] para={
new SqlParameter("@ltt",dt.Rows[0]["ltt"]),
new SqlParameter("@code",dt.Rows[0]["code"]),
new SqlParameter("@currc",dt.Rows[0]["currc"]),
new SqlParameter("@seg",dt.Rows[0]["seg"])
};
cmd.Parameters.Clear();
cmd.Parameters.AddRange(para);
cmd.executeNonQuery
}
catch(Exception error){}
}
I need to insert that data in less then 1 sec in database. Table structure