2015-09-22 16 views
4

我有一個webmethod無法在第一次嘗試期間觸發存儲過程(我猜想在建立新連接時)。我得到Internal error server作爲錯誤的Ajax消息。但是,如果我從URL地址返回,那麼存儲過程將被執行,並且頁面正常工作,因爲它們應該如此。然後再次,如果我保持頁面處於非活動狀態一段時間,然後嘗試建立新連接,則會出現同樣的問題。Ajax webmethod無法在第一次嘗試時觸發存儲過程

我花了最近2天試圖通過檢查參數,從webmethod中刪除大部分代碼來識別問題,最後我能夠將問題追溯到此存儲過程。

CREATE PROCEDURE [dbo].[spUnionServices] 
@freetext NVARCHAR(50), 
@offset int, 
@fetch int 

AS SET NOCOUNT ON; 

BEGIN 
SELECT IDphoto AS IDservice, photos.IDuser, photoCaption AS serviceTitle, photoDate as serviceDate, photoFileName AS servicePhoto, 'Photo' AS service, 
    photoPublished as servicePublished, inap, hashtags, KEY_TBL.RANK, screenName AS IDname 
    FROM photos INNER JOIN FREETEXTTABLE(photos, (photoCaption), @freetext) AS KEY_TBL ON photos.IDphoto = KEY_TBL.[KEY] 
    INNER JOIN editorDetail ON editorDetail.IDuser = photos.IDuser 
    ORDER BY RANK DESC OFFSET @offset ROWS FETCH NEXT @fetch ROWS ONLY 
END 

這裏是我如何連接到存儲過程從將WebMethod

StringBuilder SBsmallSquares = new StringBuilder(); 
SqlConnection sqlConnection1 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); 
      using (sqlConnection1) 
      { 
       SqlCommand cmd = new SqlCommand(); 
       SqlDataReader ReaderPopup; 
       cmd.CommandText = "spUnionServices"; 
       cmd.CommandType = CommandType.StoredProcedure; 
       cmd.Connection = sqlConnection1; 
       cmd.Parameters.AddWithValue("@offset", offset); 
       cmd.Parameters.AddWithValue("@fetch", fetch); 
       cmd.Parameters.AddWithValue("@freetext", fts); 

       sqlConnection1.Open(); 
       ReaderPopup = cmd.ExecuteReader(); 
       if (ReaderPopup.HasRows) 
       { 
        while (ReaderPopup.Read()) 
        { 
        //creating the string to return. Here there is no problem. 
        } 
        return SBsmallSquares.ToString(); 
       } 
      else return string.Empty; 

我將不勝感激,如果有人可以找出原因,我第一次嘗試運行時遇到此問題存儲過程。謝謝!

+1

當你調試你的服務器端webmethod代碼 - 你有什麼異常嗎? – Igor

+0

我沒有得到任何錯誤.....我能夠捕捉的唯一錯誤是來自Ajax webmethod – Gloria

+0

的「服務器內部錯誤」,這是不可能的。服務器上發生故障。你能夠在webmethod中設置斷點並停止嗎? – Igor

回答

0

您應該重試此錯誤。在可用性事件期間(例如升級),數據庫可以移動到不同的計算機,並且fdhost需要再次與SQL實例配對。通常配對過程發生在第一個自由文本查詢或需要時。您可能會第一次在這個過程中看到超時。它應該幫助你重試。如果這非常一致,那麼服務中可能存在一個錯誤並讓我們知道。我會幫你進一步調試。

+0

Azure Sql V12(這是新的Azure數據庫)發生此錯誤。事實上,由於SQL服務無法驗證簽名而導致的類似行爲,從SQL數據庫2005開始,它被稱爲服務中的錯誤,然後Microsoft使用更高版本解決它。 我在Azure支持論壇上提出了同樣的問題,但沒有人打擾回答。 – Gloria

+0

是的,錯誤是非常一致的....我測試了不同的機器上的頁面,我第一次得到相同的錯誤結果。 – Gloria

+0

嗨,我是SQL DB中此功能的開發人員。請重試Asp.Net網頁中的查詢,我們將調查爲什麼查詢超時並嘗試根據優先級獲取修復。感謝您讓我們知道。 –

0

我會把它放在註釋中,但在代碼中寫入代碼更容易。 我意識到你說你在ajax中發生錯誤,但它正在發生服務器端並被傳播回Ajax調用。因爲您的代碼中沒有任何異常處理,所以IIS使用一個具有最少細節的泛型異常來封裝異常。

你需要抓住異常服務器端並檢查它,這應該給你更多的細節,並希望通過這種洞察力弄清楚它爲什麼發生,然後修復它應該更容易。

StringBuilder SBsmallSquares = new StringBuilder(); 
SqlConnection sqlConnection1 = null; 
try 
{ 
    sqlConnection1 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); 
    SqlCommand cmd = new SqlCommand(); 
    SqlDataReader ReaderPopup; 
    cmd.CommandText = "spUnionServices"; 
    cmd.CommandType = CommandType.StoredProcedure; 
    cmd.Connection = sqlConnection1; 
    cmd.Parameters.AddWithValue("@offset", offset); 
    cmd.Parameters.AddWithValue("@fetch", fetch); 
    cmd.Parameters.AddWithValue("@freetext", fts); 

    sqlConnection1.Open(); 
    ReaderPopup = cmd.ExecuteReader(); 
    if (ReaderPopup.HasRows) 
    { 
     while (ReaderPopup.Read()) 
     { 
      //creating the string to return. Here there is no problem. 
     } 
     return SBsmallSquares.ToString(); 
    } 
    else return string.Empty; 
} 
catch (Exception ex) 
{ 
    // write this out to a text file OR (if you can) examine the exception in the debugger 
    // what you need are 
    // 0. ex.StackTrace <- the full call stack that generated the exception, now you know what method call caused it 
    // 1. ex.GetType().FullName <- the full type of the exception 
    // 2. ex.Message <- the message in the exception 
    // 3. ex.InnerException <- if this is not null then we need the type and message (1 and 2 above) again, this can recurse as many times as needed (the ex.InnerException can have an ex.InnerException.InnerException and that one can also have an InnerException, and so on) 
    // 4. some exceptions have additional details in other properties depending on the type, if you see anything usefull get that too 

    throw; // rethrow the exception because you do not want to ignore it and pretend everything succeeded (it didn't) 
} 
finally 
{ 
    if(sqlConnection1 != null) sqlConnection1.Close(); 
} 

編輯

也可以更新IIS網站配置(並在web.config我相信)經過完整的例外和細節。我不確定它是否只是在Azure中爲你託管的sql服務器,還有IIS。在後一種情況下,我不熟悉如何配置它來允許這一點,但它可能是可能的。您有時也可以指定在本地主機上運行時是否僅允許完整的異常/錯誤詳細信息,這在調試時非常有用,因爲您希望在排除故障時查看異常信息,但您更希望外部世界(公司以外)沒有看到任何敏感的內部細節。

如果您在Azure中運行IIS,然後在搜索中添加一個關於Azure的關鍵字,可以通過google瞭解如何啓用它。 Google: iis show exception

+0

伊戈爾謝謝你的回答。我想你已經錯過了我上面提到的關於我已經在webmethod外部運行SQL查詢的事實,並且從服務器收到以下錯誤:在全文查詢期間發生錯誤。常見原因包括:斷字錯誤或超時,FDHOST權限/ ACL問題,服務帳戶缺失權限,IFilter故障,FDHost和sqlservr.exe的通信通道問題等。 看起來這是一個錯誤系統中的一個錯誤。我已經在Azure支持論壇上發佈了我的問題,但從未得到答案。 – Gloria

0

我的猜測是有一個會話認證方案沒有啓動。您應該嘗試先執行獲取以允許在瀏覽器中設置Cookie。或者,仔細檢查在成功嘗試中設置的Cookie,並在頁面生成時提供信息,以對齊此問題。

相關問題