UrlReferrer代码不更新DB

时间:2014-01-10 21:07:36

标签: c# asp.net sql

我基本上试图让数据库更新cookieId并添加日期。我已经将我的代码包含在代码和存储过程中。它不会破坏网站,它只是在我从特定网站访问时不更新数据库,我无法弄清楚原因。

public partial class LifeUniformTracking : System.Web.UI.UserControl
{
    Cookie cookie = new Cookie();

    protected void Page_Load(object sender, EventArgs e)
    {
        Add(cookie.Values.CookieId);

    }

    public void Add(string CookieId)
    {
        string sproc = "LifeUniformTracking Add";
        if (!Common.EmptyNull(Request.UrlReferrer))
        {
            string RefferedFromLU = Request.UrlReferrer.ToString();
            //01-06-2014 will add CookieID to DB if user's previous URL was lifeuniform
            //addedDate updates automatically via SSMS when CookieID is added
            if (RefferedFromLU.Contains("www.lifeuniform.com"))
            {
                try
                {
                    using (DataAccess da = new DataAccess())
                    {
                        da.Set(sproc);

                        da.AddParameters("@CookieId", CookieId);

                        da.ExecuteNonQuery();
                    }
                }

                catch (Exception ex)
                {
                    GeneralError err = new GeneralError(ex, ErrorLevel.Low, "Tracking     redirect from Life Uniform website", "Failed during: " + sproc, true, false);
                }

            }
        }
    }
}


USE [ScrubsDev]
GO
/****** Object:  StoredProcedure [dbo].[LifeUniformTracking Add]    Script Date:         1/10/2014 2:57:48 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[LifeUniformTracking Add] 
-- Add the parameters for the stored procedure here
@CookieId varchar(150)
AS

BEGIN 
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
insert into LifeUniformTracking(CookieID, AddedDate, IsLifeUniform)
select @CookieId, getdate(), 1

END

1 个答案:

答案 0 :(得分:1)

您是否尝试在proc string sproc = "[dbo].[LifeUniformTracking Add]"的名称周围添加大括号? proc名称中有空格的事实意味着,当您尝试执行它时,您可能必须使用大括号引用它。