[CSHARP-422] Unable to connect to server localhost:27017: Configuration system failed to initialize. Created: 30/Mar/12  Updated: 20/Mar/14  Resolved: 12/Apr/12

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

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


 Description   

string connectionString = "mongodb://localhost:27017";
MongoServer mongo = MongoServer.Create(connectionString);
mongo.Connect(); //*******here i am getting error.
MongoDatabase database = mongo.GetDatabase("MyDB");
MongoCollection MyData = database.GetCollection<BsonDocument>("users");
BsonDocument Data = new BsonDocument {

{ "firstname", "Rick" }

};

MyData.Insert(Data);
button1.Text = "Data Inserted";
mongo.Disconnect();



 Comments   
Comment by Robert Stam [ 12/Apr/12 ]

Appears to be an issue with the user's config file and not with the C# driver.

Comment by Robert Stam [ 09/Apr/12 ]

I am assuming the problem was in your config file.

In the absence of any further feedback this bug will be closed in the next few days.

Comment by Robert Stam [ 02/Apr/12 ]

I am able to get the same stack trace by putting invalid entries into my App.config file.

Please check your config file, as that is where the problem likely lies.

I would also warn you against calling server.Disconnect as it interferes with connection pooling. Calling Connect is also not necessary (the driver connects automatically) but is harmless, unlike Disconnect which is problematic.

Comment by mahendar.gunda [ 02/Apr/12 ]

MongoDB.Driver.MongoConnectionException was unhandled
Message=Unable to connect to server localhost:27017: Configuration system failed to initialize.
Source=MongoDB.Driver
StackTrace:
at MongoDB.Driver.Internal.DirectConnector.Connect(TimeSpan timeout)
at MongoDB.Driver.MongoServer.Connect(TimeSpan timeout, ConnectWaitFor waitFor)
at MongoDB.Driver.MongoServer.Connect(ConnectWaitFor waitFor)
at MongoDB.Driver.MongoServer.ChooseServerInstance(Boolean slaveOk)
at MongoDB.Driver.MongoServer.AcquireConnection(MongoDatabase database, Boolean slaveOk)
at MongoDB.Driver.MongoCollection.InsertBatch(Type nominalType, IEnumerable documents, MongoInsertOptions options)
at MongoDB.Driver.MongoCollection.Insert(Type nominalType, Object document, MongoInsertOptions options)
at MongoDB.Driver.MongoCollection.Insert(Type nominalType, Object document)
at MongoDB.Driver.MongoCollection.Insert[TNominalType](TNominalType document)
at mongoDB_project.Form1.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\mgunda\my documents\visual studio 2010\Projects\mongoDB_project\mongoDB_project\Form1.cs:line 79
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at mongoDB_project.Program.Main() in c:\documents and settings\mgunda\my documents\visual studio 2010\Projects\mongoDB_project\mongoDB_project\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Configuration.ConfigurationErrorsException
Message=Configuration system failed to initialize
Source=System.Configuration
BareMessage=Configuration system failed to initialize
Line=0
StackTrace:
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_Sources()
at System.Diagnostics.TraceSource.Initialize()
at System.Net.Logging.InitializeLogging()
at System.Net.Logging.get_On()
at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
at MongoDB.Driver.MongoServerAddress.ToIPEndPoint(AddressFamily addressFamily)
at MongoDB.Driver.MongoServerInstance.GetIPEndPoint()
at MongoDB.Driver.Internal.MongoConnection.Open()
at MongoDB.Driver.Internal.MongoConnection.GetNetworkStream()
at MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage message, SafeMode safeMode)
at MongoDB.Driver.Internal.MongoConnection.RunCommand(String collectionName, QueryFlags queryFlags, CommandDocument command, Boolean throwOnError)
at MongoDB.Driver.MongoServerInstance.VerifyState(MongoConnection connection)
at MongoDB.Driver.MongoServerInstance.Connect(Boolean slaveOk)
at MongoDB.Driver.Internal.DirectConnector.Connect(TimeSpan timeout)
InnerException: System.Configuration.ConfigurationErrorsException
Message=Unrecognized configuration section ConfigurationManager. (C:\Documents and Settings\mgunda\my documents\visual studio 2010\Projects\mongoDB_project\mongoDB_project\bin\Debug\mongoDB_project.vshost.exe.Config line 3)
Source=System.Configuration
BareMessage=Unrecognized configuration section ConfigurationManager.
Filename=C:\Documents and Settings\mgunda\my documents\visual studio 2010\Projects\mongoDB_project\mongoDB_project\bin\Debug\mongoDB_project.vshost.exe.Config
Line=3
StackTrace:
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
InnerException:

Comment by Robert Stam [ 30/Mar/12 ]

I did a web search for "Configuration system failed to initialize" and a common cause for that is an invalid App.config file.

Can you attach your config file to the ticket?

Also, can you provide a full stack trace so we can see where the particular exception is coming from?

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