用的是 jquery 的AJAX 调用 .ashx 处理文件进行 更新和插入数据 的过程 。
有10多个人使用。但经常会出现 插入2条一样的数据 。
不知道是啥 原因。判断是没有问题。如果有问题。就一直会出错。1,2天的数据 也不多。几百条吧。偶尔会有1,2条数据 重复。找不到原因。
我现在想到可能 是
一、.ASHX,缓存也清除了,好几种方法也试过了。 context.Response.ContentType = "text/plain";
context.Response.Buffer = false;
context.Response.Cache.SetNoStore();
context.Response.Clear();
//context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
//context.Response.Cache.SetLastModified(DateTime.Now);
//context.Response.Cache.SetExpires(DateTime.Now.AddDays(-1));二、因为判断数据的时候 有用到
静态的static 过程来判断某些东西。这个会有影响吗?像下面的这个算是其中的一样判断过程。多人使用的时候STATIC过程
会有影响吗? public static int checkItemCodeAndScanCode(string strTxtCodeValue_1, string strddlItemSecondName_1)
{
string strSql_3 = "SELECT A.ID FROM LK_ItemCodeAndScanCode as A " +
" LEFT JOIN LK_Base_ItemMaster as B ON A.itemCode=B.ItemCode " +
" WHERE A.status!=3 and A.barcode=@steelCode and B.ItemSecondName=@ItemSecondName "; SqlParameter[] arrA = new SqlParameter[2];
arrA[0] = new SqlParameter("@steelCode", strTxtCodeValue_1);
arrA[1] = new SqlParameter("@ItemSecondName", strddlItemSecondName_1);
SqlDataReader sdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, strSql_3, arrA); if (!sdr.Read())
{
return 0;
}
else
{
return 1;
} sdr.Close();
sdr.Dispose(); }三、多人使用,并发操作了。是不是要加上LOCK锁来操作?这个没有用过。请问还会有什么原因会产生偶尔插入重复的数据 呢?
有10多个人使用。但经常会出现 插入2条一样的数据 。
不知道是啥 原因。判断是没有问题。如果有问题。就一直会出错。1,2天的数据 也不多。几百条吧。偶尔会有1,2条数据 重复。找不到原因。
我现在想到可能 是
一、.ASHX,缓存也清除了,好几种方法也试过了。 context.Response.ContentType = "text/plain";
context.Response.Buffer = false;
context.Response.Cache.SetNoStore();
context.Response.Clear();
//context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
//context.Response.Cache.SetLastModified(DateTime.Now);
//context.Response.Cache.SetExpires(DateTime.Now.AddDays(-1));二、因为判断数据的时候 有用到
静态的static 过程来判断某些东西。这个会有影响吗?像下面的这个算是其中的一样判断过程。多人使用的时候STATIC过程
会有影响吗? public static int checkItemCodeAndScanCode(string strTxtCodeValue_1, string strddlItemSecondName_1)
{
string strSql_3 = "SELECT A.ID FROM LK_ItemCodeAndScanCode as A " +
" LEFT JOIN LK_Base_ItemMaster as B ON A.itemCode=B.ItemCode " +
" WHERE A.status!=3 and A.barcode=@steelCode and B.ItemSecondName=@ItemSecondName "; SqlParameter[] arrA = new SqlParameter[2];
arrA[0] = new SqlParameter("@steelCode", strTxtCodeValue_1);
arrA[1] = new SqlParameter("@ItemSecondName", strddlItemSecondName_1);
SqlDataReader sdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, strSql_3, arrA); if (!sdr.Read())
{
return 0;
}
else
{
return 1;
} sdr.Close();
sdr.Dispose(); }三、多人使用,并发操作了。是不是要加上LOCK锁来操作?这个没有用过。请问还会有什么原因会产生偶尔插入重复的数据 呢?
//static没影响,
SqlDataReader sdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, strSql_3, arrA);
//都是新对象//有一种可能是使用Jquery的Ajax提交时,手快或者页面慢点了多次
当然有主键,就是如一个ID=1020 一个ID=1021 ,连在一起的啊。
触发器太麻烦。要判断的东西很多。在.NET页面上判断容易些。
是不是并发问题?LOCK?
接楼上,锁定插入方法可参考这个帖子http://topic.csdn.net/u/20111110/10/7c346036-515d-41c7-b241-264c1e743977.html