[CSHARP-152] MongoConnectionStringBuilder fails at constructor using a connection string Created: 20/Jan/11 Updated: 02/Apr/15 Resolved: 20/Jan/11 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 0.9 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Pawel Krakowiak | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I'm trying to get a server instance by using the MongoConnectionStringBuilder to read the connection string from the application configuration file. It fails stating that the connection string is in wrong format, even for the simplest of connection strings. Example: <add name="MongoDB" connectionString="mongodb://localhost" /> string connectionString = ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString; The second line will fail with the message of "System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0." StackTrace: |
| Comments |
| Comment by Robert Stam [ 20/Jan/11 ] |
|
You have to decide whether to use the standard MongoDB URL connection string syntax as used by all the drivers, or the .NET format connection string syntax used only by the C# driver. When using the URL syntax use MongoUrlBuilder instead of MongoConnectionStringBuilder. so instead of: var builder = new MongoConnectionStringBuilder(connectionString); use: var builder = new MongoUrlBuilder(connectionString); You can also pass the connection string directly to MongoServer.Create: var server = MongoServer.Create(connectionString); which looks for the "mongodb://" prefix to decide which format connection string you are using. |