0
我正在使用helpDesk Web應用程序。Web應用程序中的同步
我生成從一個功能 這些功能的獨特complaint_id可以通過3個用戶在時間,普通用戶,超級用戶和管理員當任何用戶點擊新的投訴,我在插入一個空白行
被稱爲投訴表並將該唯一的complaint_id返回給調用者。
但它可能發生,所有的3個用戶有調用函數在他同一時間,因此艾米事業問題產生的投訴ID
因爲這個功能可以共享,有可能是問題產生的ID。 我只知道它可以解決使用的線程,但我怎麼不知道 我對線程
的獲取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;
}
我想這將是明確的,現在
你說「有可能是問題產生的ID」,但沒有透露具體細節。什麼樣的問題?你的問題不是很清楚。請閱讀:http://tinyurl.com/so-hints – Oded 2011-05-07 05:22:38
發佈生成該ID的函數的代碼。 – Oded 2011-05-07 05:37:04
我不認爲你需要擔心,使用數據庫geerated的自動鍵,它會自動關心併發問題。 – kobe 2011-05-07 05:54:08