Web 应用程序中的同步
我正在开发一个帮助台 Web 应用程序。
我正在从一个函数生成一个唯一的complain_id 这些函数可以同时由 3 个用户(普通用户、超级用户和管理员)调用。
当任何用户单击“新投诉”时,
我在投诉表中插入一个空白行,并将唯一的投诉 ID 返回给调用者。但可能会发生所有 3 个用户同时调用该函数的情况,因此可能会导致生成投诉 id 时出现问题
,因为该函数是共享的,生成 id 可能会出现问题。 我只知道它可以解决使用过的线程,但我怎么不知道 我对线程了解甚少
Get id 函数是常用函数 该函数调用一个存储过程。
如果所有 3 类用户同时调用该函数会产生问题吗 这是代码
public string Getid(AddComplaint_DAO p)
{
SqlConnection con = null;
SqlCommand cmd;
string strConnection;
SqlDataAdapter adpt = null;
try
{
strConnection = ConfigurationManager.AppSettings["Connetionstring2"];
con = new SqlConnection(strConnection);
cmd = new SqlCommand("GetId", con);
cmd.Parameters.AddWithValue("@s_CompDate", SqlDateTime.Null);
cmd.Parameters.AddWithValue("@s_UserId", p.Ename);
cmd.Parameters.AddWithValue("@s_LocationId", SqlString.Null);
cmd.Parameters.AddWithValue("@s_DeptId", SqlString.Null);
cmd.Parameters.AddWithValue("@i_Extension", SqlInt32.Null);
cmd.Parameters.AddWithValue("@s_MainCat", SqlString.Null);
cmd.Parameters.AddWithValue("@s_SubCat", SqlString.Null);
cmd.Parameters.AddWithValue("@s_Item", SqlString.Null);
cmd.Parameters.AddWithValue("@s_Subject", SqlString.Null);
cmd.Parameters.AddWithValue("@s_Description", SqlString.Null);
cmd.CommandType = CommandType.StoredProcedure;
adpt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adpt.Fill(ds);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
string val = ds.Tables[0].Rows[0][0].ToString();
return val;
}
}
}
catch (SqlException ex)
{
con.Close();
string exep = ex.Message;
return null;
}
return null;
}
我想现在会很清楚了
I am working on a helpDesk Web application.
I am generating a unique complaint_id from one function
These function can be called by 3 users at time, normal user,super user and admin
when any user clicks on New complaint I am inserting a blank row in Complaint table and return that unique complaint_id to to caller .
But it may happen that all the 3 users have call the function at he same time and hence amy cause problem in generating the the Complaint id
as this function is shared there can be problem generating the id.
I only know it can solved used threads but how I don't know that
I have very little knowledge about threads
The Get id Function is the common function
this function calls a stored procedure .
will it create problem if all 3 types of users call the function at same time
here is the code
public string Getid(AddComplaint_DAO p)
{
SqlConnection con = null;
SqlCommand cmd;
string strConnection;
SqlDataAdapter adpt = null;
try
{
strConnection = ConfigurationManager.AppSettings["Connetionstring2"];
con = new SqlConnection(strConnection);
cmd = new SqlCommand("GetId", con);
cmd.Parameters.AddWithValue("@s_CompDate", SqlDateTime.Null);
cmd.Parameters.AddWithValue("@s_UserId", p.Ename);
cmd.Parameters.AddWithValue("@s_LocationId", SqlString.Null);
cmd.Parameters.AddWithValue("@s_DeptId", SqlString.Null);
cmd.Parameters.AddWithValue("@i_Extension", SqlInt32.Null);
cmd.Parameters.AddWithValue("@s_MainCat", SqlString.Null);
cmd.Parameters.AddWithValue("@s_SubCat", SqlString.Null);
cmd.Parameters.AddWithValue("@s_Item", SqlString.Null);
cmd.Parameters.AddWithValue("@s_Subject", SqlString.Null);
cmd.Parameters.AddWithValue("@s_Description", SqlString.Null);
cmd.CommandType = CommandType.StoredProcedure;
adpt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adpt.Fill(ds);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
string val = ds.Tables[0].Rows[0][0].ToString();
return val;
}
}
}
catch (SqlException ex)
{
con.Close();
string exep = ex.Message;
return null;
}
return null;
}
I guess it will be clear now
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您绝对不必担心这里的同步问题。您的数据库将为您做到这一点。我很积极。
谢谢,
克里希纳
You absolutely need not worry about synchronization here. Your database will do that for you. I am positive.
Thanks,
Krishna