开发者

Synchronization in a web application

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;
                }
            }

 开发者_Python百科       }
        catch (SqlException ex)
        {
            con.Close();
            string exep = ex.Message;
            return null;
        }
        return null;
    }

I guess it will be clear now


You absolutely need not worry about synchronization here. Your database will do that for you. I am positive.

Thanks, Krishna

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜