1. 程式人生 > >MongoDB的C#驅動報錯Server instance 127.0.0.1:27017 is no longer connected的解決方案

MongoDB的C#驅動報錯Server instance 127.0.0.1:27017 is no longer connected的解決方案

http bottom get lac soft onload nload on() kill

使用C#的MondoDB驅動,一直沒問題。結果最近,MongoCursor的ToList方法,取列表,總是報錯

Server instance 127.0.0.1:27017 is no longer connected

數據什麽的也是正常。

最後終於發現導致問題出現的原因。雖然解決方法不是很完美,但是也還解決問題了。

如果有其它好的解決方法的同學可以和我交流,微信:Jeff520888

錯誤信息如下:

<html>
    <head>
        <title>Server instance 127.0.0.1:27017 is no longer connected.</title>
        <style>
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Lucida Console";font-size: .9em}
         .marker {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
        </style>
    </head>

    <body bgcolor="white">

            <span><H1>“/”應用程序中的服務器錯誤。<hr width=100% size=1 color=silver></H1>

            <h2> <i>Server instance 127.0.0.1:27017 is no longer connected.</i> </h2></span>

            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

            <b> 說明: </b>執行當前 Web 請求期間,出現未經處理的異常。請檢查堆棧跟蹤信息,以了解有關該錯誤以及代碼中導致錯誤的出處的詳細信息。

            <br><br>

            <b> 異常詳細信息: </b>System.InvalidOperationException: Server instance 127.0.0.1:27017 is no longer connected.<br><br>

            <b>源錯誤:</b> <br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code>

執行當前 Web 請求期間生成了未經處理的異常。可以使用下面的異常堆棧跟蹤信息確定有關異常原因和發生位置的信息。</code>

                  </td>
               </tr>
            </table>

            <br>

            <b>堆棧跟蹤:</b> <br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code><pre>

[InvalidOperationException: Server instance 127.0.0.1:27017 is no longer connected.]
   MongoDB.Driver.MongoServerInstance.AcquireConnection() +140
   MongoDB.Driver.MongoServer.AcquireConnection(MongoServerInstance serverInstance) +259
   MongoDB.Driver.MongoCursorConnectionProvider.AcquireConnection() +56
   MongoDB.Driver.Operations.QueryOperation`1.KillCursor(IConnectionProvider connectionProvider, Int64 cursorId) +44
   MongoDB.Driver.Operations.<Execute>d__0.<>m__Finally6() +55
   MongoDB.Driver.Operations.<Execute>d__0.System.IDisposable.Dispose() +211
   MongoDB.Driver.Operations.<Execute>d__0.MoveNext() +598
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +406
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
   DAL.MongoHelper`1.Find(String collection, IMongoQuery query, String[] fields, String[] sortBys, Int32 skip, Int32 limit, Int64& totalNum) +934
   DAL.Service.CommonService.GetNodePageList(MongoPageCriteria criteria) +146
   DAL.Service.AppService.GetOrderListForPage(MongoPageCriteria criteria, Order ord) +5114
   Admin.BLL.AppManager.GetOrderListForPage(MongoPageCriteria criteria, Order order) +51
   Admin.View.OrderList.BindData() +807
   Admin.View.OrderList.OnLoad(EventArgs e) +516
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
</pre></code>

                  </td>
               </tr>
            </table>

            <br>

            <hr width=100% size=1 color=silver>

            <b>版本信息:</b> Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.1016

            </font>

    </body>
</html>
<!-- 
[InvalidOperationException]: Server instance 127.0.0.1:27017 is no longer connected.
   在 MongoDB.Driver.MongoServerInstance.AcquireConnection()
   在 MongoDB.Driver.MongoServer.AcquireConnection(MongoServerInstance serverInstance)
   在 MongoDB.Driver.MongoCursor`1.MongoCursorConnectionProvider.AcquireConnection()
   在 MongoDB.Driver.Operations.QueryOperation`1.KillCursor(IConnectionProvider connectionProvider, Int64 cursorId)
   在 MongoDB.Driver.Operations.QueryOperation`1.<Execute>d__0.<>m__Finally6()
   在 MongoDB.Driver.Operations.QueryOperation`1.<Execute>d__0.System.IDisposable.Dispose()
   在 MongoDB.Driver.Operations.QueryOperation`1.<Execute>d__0.MoveNext()
   在 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   在 DAL.MongoHelper`1.Find(String collection, IMongoQuery query, String[] fields, String[] sortBys, Int32 skip, Int32 limit, Int64& totalNum)
   在 DAL.Service.CommonService.GetNodePageList(MongoPageCriteria criteria)
   在 DAL.Service.AppService.GetOrderListForPage(MongoPageCriteria criteria, Order ord)
   在 Admin.BLL.AppManager.GetOrderListForPage(MongoPageCriteria criteria, Order order)
   在 Admin.View.OrderList.BindData()
   在 Admin.View.OrderList.OnLoad(EventArgs e)
   在 System.Web.UI.Control.LoadRecursive()
   在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
[HttpUnhandledException]: 引發類型為“System.Web.HttpUnhandledException”的異常。
   在 System.Web.UI.Page.HandleError(Exception e)
   在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   在 System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   在 System.Web.UI.Page.ProcessRequest()
   在 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   在 System.Web.UI.Page.ProcessRequest(HttpContext context)
   在 ASP.view_orderlist_aspx.ProcessRequest(HttpContext context) 位置 c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\7b58857c\5cb9b318\App_Web_0b0m0xbf.18.cs:行號 0
   在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
--><!-- 
此錯誤頁可能包含敏感信息,因為 ASP.NET 通過 <customErrors mode="Off"/> 被配置為顯示詳細錯誤消息。請考慮在生產環境中使用 <customErrors mode="On"/> 或 <customErrors mode="RemoteOnly"/>。-->

MongoDB的C#驅動報錯Server instance 127.0.0.1:27017 is no longer connected的解決方案