[CSHARP-549] Connection string with multiple hosts will not create a valid connection Created: 24/Aug/12  Updated: 20/Mar/14  Resolved: 27/Aug/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.5
Fix Version/s: 1.6

Type: Bug Priority: Major - P3
Reporter: Erik Holm Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MongoDB 2.0.2 DB running on CentOs 6.0 connecting from Windows Server 2008 R2 using the C# driver version 1.5


Issue Links:
Depends
depends on CSHARP-500 If host names in replica set connecti... Closed

 Description   

We are unable to create a connection from our web server to our DB server using a connection string in any of the formats below:

mongodb://XXXUSERXXX:XXXPASSWORDXXX@T02-VM-XXXX01.vss-eng.com,XXXUSERXXX:XXXPASSWORDXXX@T02-VM-XXXX02.vss-eng.com,XXXUSERXXX:XXXPASSWORDXXX@T02-VM-XXXX03.vss-eng.com/NH_DEVICEDATA?replicaSet=NH_Data_01

mongodb://XXXUSERXXX:XXXPASSWORDXXX@ T02-VM-XXXX01.vss-eng.com:27017, T02-VM-XXXX02.vss-eng.com:27017/NH_DEVICEDATA
mongodb://XXXUSERXXX:XXXPASSWORDXXX@ T02-VM-XXXX01.vss-eng.com:27017, T02-VM-XXXX02.vss-eng.com:27017/NH_DEVICEDATA?replicaSet=NH_Data_01

We are trying to connect to a replica set of 3 seperate VM servers and the error we continue to recieve is:

Type: MongoDB.Driver.MongoConnectionException
Message: Unable to connect to the primary member of the replica set.
Source: MongoDB.Driver
InnerExceptions: System.Exception[]
StackTrace: at MongoDB.Driver.Internal.ReplicaSetConnector.Connect(TimeSpan timeout, ConnectWaitFor waitFor)
at MongoDB.Driver.MongoServer.Connect(TimeSpan timeout, ConnectWaitFor waitFor)
at MongoDB.Driver.MongoServer.ChooseServerInstance(Boolean slaveOk)
at MongoDB.Driver.MongoServer.AcquireConnection(MongoDatabase database, Boolean slaveOk)
at MongoDB.Driver.MongoCursorEnumerator`1.AcquireConnection()
at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst()
at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext()
at MongoDB.Driver.MongoDatabase.GetCollectionNames()
at MongoDB.Driver.MongoDatabase.CollectionExists(String collectionName)
at VSS.Nighthawk.EntityModels.Dao.Mongo.MongoStorage`1.SetupCollection(String collectionName, IMongoCollectionOptions collectionOptions, Func`1 runCustomClassMap) in C:\TFS\Nighthawk\NH\RC\2.5.0.3_OEMDF\Server\CommonLibrary\EntityModels\Dao\Mongo\MongoStorage.cs:line 257
at VSS.Nighthawk.EntityModels.Dao.Mongo.MongoStorage`1..ctor(IMongoCollectionOptions collectionOptions, Func`1 runCustomClassMap) in C:\TFS\Nighthawk\NH\RC\2.5.0.3_OEMDF\Server\CommonLibrary\EntityModels\Dao\Mongo\MongoStorage.cs:line 32

We have not modified the 1.5 driver in any way.

The replica set is correctly set up. The output of the rs.isMaster() command is below:

PRIMARY> rs.isMaster()
{
"setName" : "NH_Data_01",
"ismaster" : true,
"secondary" : false,
"hosts" : [
"T02-VM-XXXX01:27017",
"T02-VM-XXXX02:27017"
],
"passives" : [
"T02-VM-XXXX03:27017"
],
"primary" : "T02-VM-XXXX01:27017",
"me" : "T02-VM-XXXX01:27017",
"maxBsonObjectSize" : 16777216,
"ok" : 1
}

Please let us know what the issue is with the connection string capability within the Driver.



 Comments   
Comment by Robert Stam [ 27/Aug/12 ]

Related issue CSHARP-500 has been resolved and closed.

Comment by Robert Stam [ 24/Aug/12 ]

See also: https://jira.mongodb.org/browse/CSHARP-500

Comment by Robert Stam [ 24/Aug/12 ]

The first connection string is not valid. The username/password can only appear once.

The second and third connection strings appear to be syntactically valid (assuming the spaces I see are copy and paste artifacts, if not remove the spaces).

It appears that there is a mismatch between the names of the hosts on the connection string and the replica set config. That could be the issue. Try making them the same.

T02-VM-XXXX01.vss-eng.com vs T02-VM-XXXX01:27017

Let me know if that helps.

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