Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-255

SocketException on MongoServer.Connect()

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.1, 1.2
    • Affects Version/s: 1.1
    • Component/s: None
    • Environment:
      Running on Azure connecting to a local VM running 3 mongod.exe as replica sets

      This mongo url fails with the 1.1 c# driver and works with the 1.0 driver

      mongodb://xxxx:40000,xxxx:40001,xxxx:40002/?ipv6=true;replicaSet=xq;safe=true

      System.Net.Sockets.SocketException: No connection could be made
      because the target machine actively refused it [::1]:40000
      at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,
      SocketAddress socketAddress)
      at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
      at System.Net.Sockets.TcpClient.Connect(IPEndPoint remoteEP)
      at MongoDB.Driver.Internal.MongoConnection.Open() in
      C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line
      266
      at MongoDB.Driver.Internal.MongoConnection.GetNetworkStream() in
      C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line
      409
      at MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage
      message, SafeMode safeMode) in
      C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line
      403
      at MongoDB.Driver.Internal.MongoConnection.RunCommand(String
      collectionName, QueryFlags queryFlags, CommandDocument command) in
      C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line
      296
      at MongoDB.Driver.MongoServerInstance.Connect(Boolean slaveOk) in
      C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServerInstance.cs:line
      254
      at MongoDB.Driver.Internal.ReplicaSetConnector.ConnectWorkItem(Object
      argsObject) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\ReplicaSetConnector.cs:line
      100
      — End of inner exception stack trace —
      at MongoDB.Driver.Internal.ReplicaSetConnector.Connect(TimeSpan
      timeout) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\ReplicaSetConnector.cs:line
      87
      at MongoDB.Driver.MongoServer.Connect(TimeSpan timeout) in
      C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServer.cs:line
      435
      at MongoDB.Driver.MongoServer.Connect() in
      C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServer.cs:line
      415
      at IQ.IR.Data.Configuration.GetMongoDB(String connection) in
      C:\Dev\XQ.Service\IQ.IR.Data\Configuration.cs:line 52

      This is the code...

      static MongoDatabase GetMongoDB(string connection)
      {
      const string testBox = "xxxx";
      var addr1 = new MongoServerAddress(testBox, 40000);
      var addr2 = new MongoServerAddress(testBox, 40001);
      var addr3 = new MongoServerAddress(testBox, 40002);
      MongoUrlBuilder url = new MongoUrlBuilder
      {
      IPv6 = true,
      SafeMode = SafeMode.True,
      Servers = new List<MongoServerAddress>

      { addr1, addr2, addr3 }

      ,
      ConnectionMode = ConnectionMode.ReplicaSet,
      ReplicaSetName = "xq"
      };

      try

      { var mongo = MongoServer.Create(url.ToMongoUrl()); mongo.Connect(); return mongo.GetDatabase("xq"); }

      catch (Exception ex)
      {
      throw new Exception(string.Format("<<

      {0}

      >>

      {1}

      ",
      url.ToMongoUrl(), ex));
      }
      }

      I put a test in to see if the Host value resolves to an IP and it does (IPv6).

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            woaksie John Woakes
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: