c# Unable to connect to a member of the replica set matching the read preference

zyh_1988 2016-12-13 02:37:36
Unable to connect to a member of the replica set matching the read preference Primary: 未将对象引用设置到对象的实例。.]
MongoDB.Driver.Internal.MultipleInstanceMongoServerProxy.ThrowConnectionException(ReadPreference readPreference) +535
MongoDB.Driver.Internal.MultipleInstanceMongoServerProxy.Connect(TimeSpan timeout, ReadPreference readPreference) +677
MongoDB.Driver.Internal.MultipleInstanceMongoServerProxy.ChooseServerInstance(ReadPreference readPreference) +182
MongoDB.Driver.Internal.DiscoveringMongoServerProxy.ChooseServerInstance(ReadPreference readPreference) +110
MongoDB.Driver.MongoServer.AcquireConnection(MongoDatabase database, ReadPreference readPreference) +367
MongoDB.Driver.MongoCursorEnumerator`1.AcquireConnection() +108
MongoDB.Driver.MongoCursorEnumerator`1.GetFirst() +80
MongoDB.Driver.MongoCursorEnumerator`1.MoveNext() +203
System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +121
MongoDB.Driver.MongoCollection.FindOneAs(IMongoQuery query) +176
MongoDB.Driver.MongoCollection.RunCommandAs(Type commandResultType, IMongoCommand command) +123
MongoDB.Driver.MongoDatabase.RunCommandAs(Type commandResultType, IMongoCommand command) +64
MongoDB.Driver.MongoDatabase.RunCommandAs(IMongoCommand command) +120
MongoDB.Driver.MongoDatabase.RunCommand(IMongoCommand command) +60
MongoDB.Driver.MongoCursor.Size() +374
MongoDB.Driver.Linq.SelectQuery.<TranslateCount>b__2(IEnumerable source) +65
MongoDB.Driver.Linq.SelectQuery.Execute() +2385
MongoDB.Driver.Linq.MongoQueryProvider.Execute(Expression expression) +132
MongoDB.Driver.Linq.MongoQueryProvider.Execute(Expression expression) +227
System.Linq.Queryable.Count(IQueryable`1 source) +196
Webdiyer.WebControls.Mvc.PageLinqExtensions.ToPagedList(IQueryable`1 allItems, Int32 pageIndex, Int32 pageSize) +248
WindInfoSys.Code.BLL.ManageTargetService.tuijian(Int32 page, Int32 maxPage) in D:\ZyhMyData\CompanyTask\2016\11\Mongodb--WinSysInfo\WindInfoSys_Mongo_Lastest\Web_Code\Code\BLL\BaseService.cs:801
WindInfoSys.Controllers.BaseController.Important() in D:\ZyhMyData\CompanyTask\2016\11\Mongodb--WinSysInfo\WindInfoSys_Mongo_Lastest\Web_Code\Controllers\BaseController.cs:1896
lambda_method(Closure , ControllerBase , Object[] ) +101
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +59
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +435
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +60
System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +145
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +433
System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +72
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +323
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +844
System.Web.Mvc.Controller.ExecuteCore() +130
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +123
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +68
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +41
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +39
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +137
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +63
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9644037
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
...全文
270 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyh_1988 2016-12-15
  • 打赏
  • 举报
回复
看来又要沉了。。。。
zyh_1988 2016-12-14
  • 打赏
  • 举报
回复
我的问题 主要就是 多线程访问 才出上面的问题,是不是多线程访问路由服务器 ,mongodb 集群在切换的时候加锁了??
zyh_1988 2016-12-14
  • 打赏
  • 举报
回复
引用 3 楼 Chinajiyong 的回复:
http://www.cnblogs.com/yaoxing/p/cant-connect-to-mongodb-replica-set.html
我的 链接的 是 mongodb 集群 private static List<MongoServerAddress> addresses = new List<MongoServerAddress>() { new MongoServerAddress("192.168.1.xx1" , 20000), new MongoServerAddress("192.168.1.xx2" , 20000), new MongoServerAddress("192.168.1.xx3" , 20000) }; MongoServerSettings set = new MongoServerSettings(); set.Servers = addresses; set.ConnectionMode = ConnectionMode.ShardRouter; set.ConnectTimeout = new TimeSpan(0, 0, 0, 60, 0); //set.ReplicaSetName = "shard1"; set.SlaveOk = true; set.ReadPreference = new ReadPreference(ReadPreferenceMode.Secondary); _server = MongoServer.Create(set); 求大神指点啊
EnForGrass 2016-12-14
  • 打赏
  • 举报
回复
http://www.cnblogs.com/yaoxing/p/cant-connect-to-mongodb-replica-set.html
zyh_1988 2016-12-13
  • 打赏
  • 举报
回复
http://stackoverflow.com/questions/16068710/c-sharp-unable-to-connect-to-a-member-of-the-replica-set-matching-the-read-prefe 上面的链接 我也看了 我 的mongoserverlist 添加的是 路由服务器 单线程访问 没问题 多线程 就报上面的错误

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧