本文介绍了插入不正常ADO.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我非常沮丧,因为这个SP在SSMS中可以正常执行,但是使用我的项目将执行5次中的1次。我只是要发布我的代码,看看有没有人看到我不知道的东西。我正在使用Sql Azure DB:



This has me so frustrated, because this SP works fine executing in SSMS, but will execute 1 out of 5 times using my project. I am just going to post my code and see if anyone sees something I don't. I am using Sql Azure DB:

//get variables needed
MembershipUser newUser = Membership.GetUser(RegisterUser.UserName);
Guid newUserGuid = (Guid)newUser.ProviderUserKey;

            //Insert Initial Registration data
SqlConnection cn = new    SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString());
SqlCommand cmd = new SqlCommand("dbo.spInsertInitialUserConfirmationInfo", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@fkUserId", newUserGuid.ToString());
            cn.Open();
            cmd.BeginExecuteNonQuery();
            cn.Close();

推荐答案

cn.Open();
            IAsyncResult result = cmd.BeginExecuteNonQuery();
            try
            {
                cmd.EndExecuteNonQuery(result);
                Response.Redirect("~/MyAccount");
            }
            catch (Exception ex)
            {
                errorsOccured.Text = "An error occurred: " + ex.Message;
            }
            finally
            {
                cn.Close();
            }



这篇关于插入不正常ADO.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 17:58