[CSHARP-2070] A timeout occured after 30000ms selecting a server using CompositeServerSelector Created: 23/Oct/17  Updated: 27/Oct/23  Resolved: 22/Jan/18

Status: Closed
Project: C# Driver
Component/s: Configuration, Connectivity
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Ibnu Setiawan Assignee: Robert Stam
Resolution: Works as Designed Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File MongoContext.cs    

 Description   

I want to learn C# ASP MVC 5 with mongodb .

in Tutorial at http://www.c-sharpcorner.com/article/simple-crud-operation-using-asp-net-mvc-and-mongodb/ ,

My Connection in Attachment .

at command :
var carDetails = _dbContext._database.GetCollection<CarModel>("CarModel").FindAll().SetLimit(10).ToList();

I have a Error :

A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = WritableServerSelector, LatencyLimitingServerSelector

{ AllowedLatencyRange = 00:00:00.0150000 }

}. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "

{ ClusterId : 1, EndPoint : "Unspecified/localhost:27017" }

", EndPoint: "Unspecified/localhost:27017", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> MongoDB.Driver.MongoAuthenticationException: Unable to authenticate username 'demouser' on database 'CarDatabase'. ---> MongoDB.Driver.MongoCommandException: Command authenticate failed: auth failed.
at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.ProcessReply(ConnectionId connectionId, ReplyMessage`1 reply)
at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.<ExecuteAsync>d__11.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.Core.Authentication.MongoDBCRAuthenticator.<AuthenticateAsync>d__7.MoveNext()
— End of inner exception stack trace —
at MongoDB.Driver.Core.Authentication.MongoDBCRAuthenticator.<AuthenticateAsync>d__7.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.Core.Authentication.AuthenticationHelper.<AuthenticateAsync>d__1.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.Core.Connections.ConnectionInitializer.<InitializeConnectionAsync>d__3.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__48.MoveNext()
— End of inner exception stack trace —
at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__48.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at MongoDB.Driver.Core.Servers.ServerMonitor.<HeartbeatAsync>d__27.MoveNext()" }] }



 Comments   
Comment by James Kovacs [ 08/Mar/23 ]

For more information, see Why Does the Driver Throw a Timeout During Server Selection? in the MongoDB .NET/C# Driver FAQ.

Comment by Jeffrey Yemin [ 23/Oct/17 ]

It looks like the root cause is an authentication error:

Unable to authenticate username 'demouser' on database 'CarDatabase'.

Please double check whether a user with the name ''demouser'' is defined in the 'CarDatabase' database, and that the password that you provided is correct. You can confirm in the mongo shell like this:

MongoDB Enterprise > use CarDatabase
switched to db CarDatabase
MongoDB Enterprise > db.auth('demouser', 'password')

Generated at Wed Feb 07 21:41:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.