I am using the following Web method.. its work fast on local host , but on Domain hosted server .. its works odd , i;e; some time its work fast about (1-3 sec) and some take about 10-14 sec to process.. how do i make it work properly and fast.. and what are possible solution for it..
here is my code
[WebMethod]
public static string DisplayMessage(string name, string price,string obj, string id)
{
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString);
//Creating Delay""
conn.Open();
string emailid =HttpContext.Current.User.Identity.Name;
string date = DateTime.Now.ToString();
string s = HttpContext.Current.User.Identity.Name;
string[] split = s.Split('@');
string username = split[0];
SqlCommand cmd1 = new SqlCommand(("select * from cartnew where productid ='" + id + "'and userid='" + UserId + "' "), conn);
DataSet dss1 = new DataSet();
SqlDataAdapter adpr1 = new SqlDataAdapter();
adpr1.SelectCommand = cmd1;
adpr1.Fill(dss1);
int k = dss1.Tables[0].Rows.Count;
if (k == 0)
{
string sql = string.Format(@"INSERT INTO [eshop].[dbo].[cartnew]
([prodname]
,[prodprice],[produrl],[userid],[quantity],[productid],[emailid],[username],[date],[subtotal])
VALUES
('{0}'
,'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')", name, price, obj, UserId, '1', id, emailid, username, date, price);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
else
{
SqlCommand cmd2 = new SqlCommand("select * from cartnew where productid ='" + id + "'and userid='" + UserId + "'", conn);
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = cmd2;
DataSet ds = new DataSet();
adp.Fill(ds);
int val = int.Parse(ds.Tables[0].Rows[0]["quantity"].ToString());
double p = double.Parse(ds.Tables[0].Rows[0]["prodprice"].ToString());
string s1 = ds.Tables[0].Rows[0]["productid"].ToString();
string s2 = ds.Tables[0].Rows[0]["userid"].ToString();
val = val + 1;
p = p * val;
SqlCommand cmd3 = new SqlCommand("update cartnew set quantity='" + val + "',subtotal='" + p + "' where productid ='" + s1 + "'and userid='" + s2 + "'", conn);
cmd3.ExecuteNonQuery();
}
conn.Close();
return " ";
}