2017-06-13 15 views
1

Mongodbに接続するときにこのエラーが発生します。私は本当にこのエラーが何であるかわからない。MongoDB認証でのエラー

タイムアウトCompositeServerSelector {:プライマリ}}、{LatencyLimitingServerSelector AllowedLatencyRange = 00:00:00.0150000}セレクタ= ReadPreferenceServerSelector {ReadPreferenceを= {モード}使用してサーバを選択30000ms後に起こりました。クラスタ状態のクライアントビューは{ClusterId: "1"、ConnectionMode: "Automatic"、タイプ: "Unknown"、状態: "Disconnected"、サーバー:[{ServerId: "{ClusterId:1、EndPoint:" 123.123.123.123: "MongoDB.Driver.MongoConnectionException:サーバーへの接続を開く際に例外が発生しました。--- > MongoDB.Driver.MongoAuthenticationException:saslプロトコルメカニズムSCRAM-SHA-1を使用して認証できません---> MongoDB.Driver.MongoCommandException:コマンドsaslStartが失敗しました:認証が失敗しました.. MongoDB.Driver.Core.WireProtocol.CommandWireProtocol 1.ProcessReply(ConnectionId connectionId, ReplyMessage 1 MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.d__11.MoveNext()---例外がスローされた前の場所からのスタックトレースの終了--- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(タスクタスク)at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAn MongoDB.Driver.Core.Authentication.SaslAuthenticator.d__7.MoveNext()---内部例外スタックトレースの終了--- MongoDB.Driver.Core.Authentication.SaslAuthenticator.d__7.MoveNext() - でのdDebuggerNotification(タスクタスク) - 例外がスローされた前の場所からのスタックトレースの終了--- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(タスクタスク)at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(タスクタスク)MongoDB.Driver.Core .Authentication.AuthenticationHelper.d__1.MoveNext()---例外がスローされた前の場所からのスタックトレースの終了--- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(タスクタスク)(System.Runtime.CompilerServices.TaskAwaiter) MongoDB.Driver.Core.Connections.ConnectionInitializer.d__3.MoveNext()---例外がスローされた前の場所からのスタックトレースの終了--- System.Runtime.CompilerServices.TaskAwaiter.ThroでのHandleNonSuccessAndDebuggerNotification(タスクタスク) MongoDB.Driver.Core.Connections.BinaryConnection.d__48.MoveNext()---内部例外スタックトレースの終了--- MongoDBでのSystem.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(タスクタスク)のwForNonSuccess(タスクタスク)。 Driver.Core.Connections.BinaryConnection.d__48.MoveNext()---例外がスローされた前の場所からのスタックトレースの終了--- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)at System.Runtime.CompilerServices MongoDB.Driver.Core.Servers.ServerMonitor.d__27.MoveNextでSystem.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(タスクのタスク)で.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(タスクのタスク)()」}]}

ことができます誰も私を助けてくれますか?

MongoDBバージョン3.4.4を使用しています。

お願いします。ありがとうございます。 MongoDBのログイン

、それは

SCRAM-SHA-1認証は、クライアント111.111.111.111:12312からGrandnodeにUSERNAMEEXAMPLEのために失敗したことを述べています。 UserNotFound:ユーザー名が見つかりませんでしたexampleexample @ Grandnode

GrandnodeはGrandnodeプロジェクトで作成したいデータベース名です。

この問題を解決するにはどうすればよいですか?接続しているときは、このブロックを追加し、認証情報を設定していないよう

+0

エラーが誤った認証資格情報を提供を意味します。有効なユーザー名とパスワードを持っていることを確認してください。あなたが信じて、それらの資格情報を確認できると思うなら、mongoシェルのような別のクライアントから接続できるようにして、あなたの質問への接続先のコードを含めます。これはスタックトレースよりも使いやすいものです。 –

+0

私はRobomongo経由でmongodbサーバーに接続できますが、C#コードでは接続できません。 – Desmond

+0

あなたに質問されたようなコードを表示してください。 –

答えて

1

が見える -

string username = "user"; 
string password = "password"; 
string mongoDbAuthMechanism = "SCRAM-SHA-1"; 
MongoInternalIdentity internalIdentity = 
      new MongoInternalIdentity("admin", username); 
PasswordEvidence passwordEvidence = new PasswordEvidence(password); 
MongoCredential mongoCredential = 
    new MongoCredential(mongoDbAuthMechanism, 
      internalIdentity, passwordEvidence); 
List<MongoCredential> credentials = 
      new List<MongoCredential>() {mongoCredential}; 


MongoClientSettings settings = new MongoClientSettings(); 
// comment this line below if your mongo doesn't run on secured mode 
settings.Credentials = credentials; 
String mongoHost = "127.0.0.1"; 
MongoServerAddress address = new MongoServerAddress(mongoHost); 
settings.Server = address; 

MongoClient client = new MongoClient(settings);   

var mongoServer = client.GetDatabase("myDb"); 
var coll = mongoServer.GetCollection<Employee>("Employees"); 

// any stubbed out class 
Employee emp = new Employee() 
{ 
    Id = Guid.NewGuid().ToString(), 
    Name = "Employee_" + DateTime.UtcNow.ToString("yyyy_MMMM_dd") 
}; 

coll.InsertOne(emp); 
+0

これは、2.6のバージョンのドライバで.net core 2を使用して私の問題を修正するのに役立ちました。 –