2014-01-10 97 views
0

我基本上試圖讓數據庫更新cookieId和添加日期。我已經將我的代碼包含在編碼和存儲過程中。它不會中斷站點,它只是在我訪問特定站點時不更新數據庫,我無法弄清楚原因。UrlReferrer代碼不更新DB

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 
+0

你有什麼錯誤嗎? – SLaks

+0

沒有錯誤,但通過它的一步跳出這裏的代碼:if(!Common.EmptyNull(Request.UrlReferrer)) – Wintermute

+0

然後可能的UrlReferrer爲null,如果我假設'Common.EmptyNull'是正確的。我無法確定,因爲那是自定義代碼。只有在客戶端點擊鏈接時纔會填充UrlReferrer。如果存在重定向,則引用者將爲空。檢查此參考:http://stackoverflow.com/questions/3732742/asp-net-response-redirect-not-populating-url-referrer – akousmata

回答

1

您是否嘗試過在proc string sproc = "[dbo].[LifeUniformTracking Add]"的名稱周圍添加大括號? proc名稱中有一個空格的事實意味着,只要您嘗試執行它,就可能需要使用大括號來引用它。

+0

我可能會在最終代碼中保留該建議,但它不能解決問題。謝謝,不過。 – Wintermute