Re: [mongodb-user] Newbie - Using C# Driver (10Gen) - Getting "A non-recoverable error occurred during a database lookup."

1,447 views
Skip to first unread message

Robert Stam

unread,
Jul 18, 2012, 7:29:57 PM7/18/12
to mongod...@googlegroups.com
I haven't seen this before, but looking at the stack trace the error is coming straight from a DNS lookup.

Can you show us your code?

On Wed, Jul 18, 2012 at 7:01 PM, Juhi Ghogh <juhi....@gmail.com> wrote:
Using MongoDB: mongodb-win32-x86_64-2.0.6  (followed standard setup given in  http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/)
C# Driver: CSharpDriver-1.5.0.4566  (Tried the lower version as well).


Did the standard quickstart setup described in http://www.mongodb.org/display/DOCS/CSharp+Driver+Quickstart

Keep getting the following error when I run the program: 

MongoDB.Driver.MongoConnectionException was unhandled
  Message=Unable to connect to server localhost:27017: A non-recoverable error occurred during a database lookup.
  Source=MongoDB.Driver
  StackTrace:
       at MongoDB.Driver.Internal.DirectConnector.Connect(TimeSpan timeout) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\DirectConnector.cs:line 66
       at MongoDB.Driver.MongoServer.Connect(TimeSpan timeout, ConnectWaitFor waitFor) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServer.cs:line 590
       at MongoDB.Driver.MongoServer.Connect(ConnectWaitFor waitFor) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServer.cs:line 558
       at MongoDB.Driver.MongoServer.ChooseServerInstance(Boolean slaveOk) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServer.cs:line 1296
       at MongoDB.Driver.MongoServer.AcquireConnection(MongoDatabase database, Boolean slaveOk) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServer.cs:line 1188
       at MongoDB.Driver.MongoCursorEnumerator`1.AcquireConnection() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 210
       at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 223
       at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 141
       at MongoDB.Driver.MongoDatabase.GetCollectionNames() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 650
       at MongoDB.Driver.MongoDatabase.CollectionExists(String collectionName) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 302
       at TryMongoDB.Program.Main(String[] args) in t:\visual studio 2010\Projects\TryMongoDB\TryMongoDB\Program.cs:line 23
       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.Net.Sockets.SocketException
       Message=A non-recoverable error occurred during a database lookup
       Source=System
       ErrorCode=11003
       NativeErrorCode=11003
       StackTrace:
            at System.Net.Dns.GetAddrInfo(String name)
            at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
            at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
            at MongoDB.Driver.MongoServerAddress.ToIPEndPoint(AddressFamily addressFamily) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServerAddress.cs:line 194
            at MongoDB.Driver.MongoServerInstance.GetIPEndPoint() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServerInstance.cs:line 211
            at MongoDB.Driver.Internal.MongoConnection.Open() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 364
            at MongoDB.Driver.Internal.MongoConnection.GetNetworkStream() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 529
            at MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage message, SafeMode safeMode) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 488
            at MongoDB.Driver.Internal.MongoConnection.RunCommand(String collectionName, QueryFlags queryFlags, CommandDocument command, Boolean throwOnError) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 392
            at MongoDB.Driver.MongoServerInstance.VerifyState(MongoConnection connection) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServerInstance.cs:line 428
            at MongoDB.Driver.MongoServerInstance.Connect(Boolean slaveOk) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServerInstance.cs:line 348
            at MongoDB.Driver.Internal.DirectConnector.Connect(TimeSpan timeout) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\DirectConnector.cs:line 52
       InnerException: 

What am I doing wrong?

Thanks,
Juhi

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

Juhi Ghosh

unread,
Jul 19, 2012, 9:27:59 AM7/19/12
to mongod...@googlegroups.com
Here it is:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;

namespace TryMongoDB
{
    public class Entity
    {
        public ObjectId Id { get; set; }
        public string Name { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var connectionString = "mongodb://localhost/";
            var server = MongoServer.Create(connectionString);
            var database = server.GetDatabase("test");
            //Console.WriteLine( database.CollectionExists("test"));
            var collection = database.GetCollection<Entity>("entities");

            var entity = new Entity { Name = "Tom" };
            collection.Insert(entity);
            var id = entity.Id;

            var query = Query.EQ("_id", id);
            entity = collection.FindOne(query);

            entity.Name = "Dick";
            collection.Save(entity);

            var update = Update.Set("Name", "Harry");
            collection.Update(query, update);

            collection.Remove(query);
        }
    }
}


On Wednesday, July 18, 2012 7:29:57 PM UTC-4, Robert Stam wrote:
I haven't seen this before, but looking at the stack trace the error is coming straight from a DNS lookup.

Can you show us your code?

craiggwilson

unread,
Jul 19, 2012, 9:55:46 AM7/19/12
to mongod...@googlegroups.com
What version of the driver are you using?

Juhi Ghosh

unread,
Jul 19, 2012, 9:59:02 AM7/19/12
to mongod...@googlegroups.com

craiggwilson

unread,
Jul 19, 2012, 10:03:06 AM7/19/12
to mongod...@googlegroups.com
So, is the database running?  Can you do this from the command line and does it connect?

c:\{wherever mongodb is installed}\mongo.exe

Juhi Ghosh

unread,
Jul 19, 2012, 10:46:12 AM7/19/12
to mongod...@googlegroups.com
Yes. I am able to connect from command line. I created databases, collections etc.

craiggwilson

unread,
Jul 19, 2012, 10:51:18 AM7/19/12
to mongod...@googlegroups.com
Can you try changing your connection string to use 127.0.0.1 instead of localhost?  I want to see if dns is getting in the way...  BTW: have you hacked your hosts file?

Juhi Ghosh

unread,
Jul 19, 2012, 11:08:30 AM7/19/12
to mongod...@googlegroups.com
I tried 127.0.0.1. Get the following error.

MongoDB.Driver.MongoConnectionException was unhandled
  Message=Unable to connect to server 127.0.0.1:27017: An invalid argument was supplied.
  Source=MongoDB.Driver
  StackTrace:
       at MongoDB.Driver.Internal.DirectConnector.Connect(TimeSpan timeout) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\DirectConnector.cs:line 66
       at MongoDB.Driver.MongoServer.Connect(TimeSpan timeout, ConnectWaitFor waitFor) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServer.cs:line 590
       at MongoDB.Driver.MongoServer.Connect(ConnectWaitFor waitFor) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServer.cs:line 558
       at MongoDB.Driver.MongoServer.ChooseServerInstance(Boolean slaveOk) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServer.cs:line 1296
       at MongoDB.Driver.MongoServer.AcquireConnection(MongoDatabase database, Boolean slaveOk) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServer.cs:line 1188
       at MongoDB.Driver.MongoCollection.InsertBatch(Type nominalType, IEnumerable documents, MongoInsertOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 1060
       at MongoDB.Driver.MongoCollection.Insert(Type nominalType, Object document, MongoInsertOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 942
       at MongoDB.Driver.MongoCollection.Insert(Type nominalType, Object document) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 926
       at MongoDB.Driver.MongoCollection.Insert[TNominalType](TNominalType document) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 890
       at MongoDB.Driver.MongoCollection`1.Insert(TDefaultDocument document) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 1738
       at TryMongoDB.Program.Main(String[] args) in t:\visual studio 2010\Projects\TryMongoDB\TryMongoDB\Program.cs:line 27
       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.Net.Sockets.SocketException
       Message=An invalid argument was supplied
       Source=System
       ErrorCode=10022
       NativeErrorCode=10022
       StackTrace:
            at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
            at System.Net.Sockets.TcpClient.initialize()
            at System.Net.Sockets.TcpClient..ctor(AddressFamily family)
            at MongoDB.Driver.Internal.MongoConnection.Open() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 365
            at MongoDB.Driver.Internal.MongoConnection.GetNetworkStream() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 529
            at MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage message, SafeMode safeMode) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 488
            at MongoDB.Driver.Internal.MongoConnection.RunCommand(String collectionName, QueryFlags queryFlags, CommandDocument command, Boolean throwOnError) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 392
            at MongoDB.Driver.MongoServerInstance.VerifyState(MongoConnection connection) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServerInstance.cs:line 428
            at MongoDB.Driver.MongoServerInstance.Connect(Boolean slaveOk) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServerInstance.cs:line 348
            at MongoDB.Driver.Internal.DirectConnector.Connect(TimeSpan timeout) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\DirectConnector.cs:line 52
       InnerException: 


Here is my hosts file:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
# 127.0.0.1       localhost
# ::1             localhost

craiggwilson

unread,
Jul 19, 2012, 11:40:38 AM7/19/12
to mongod...@googlegroups.com
Ok, so according to your original error, this is what msdn says about the error from here:  http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx.  Note that the referenced "database" is NOT mongodb, but rather the native database used for network related stuff.

WSANO_RECOVERY
11003

This is a nonrecoverable error.

This indicates that some sort of nonrecoverable error occurred during a database lookup. This may be because the database files (for example, BSD-compatible HOSTS, SERVICES, or PROTOCOLS files) could not be found, or a DNS request was returned by the server with a severe error.


Seems like something odd is going on with your computer.  Are you able to ping localhost?

Juhi Ghosh

unread,
Jul 19, 2012, 11:50:16 AM7/19/12
to mongod...@googlegroups.com
Yes Ping works. The machines's IP also, still no luck. I tried installing on another machine, same issue. Looks like some firewall/network setting. 

Juhi Ghosh

unread,
Jul 19, 2012, 2:43:55 PM7/19/12
to mongod...@googlegroups.com
Figured it out. We were running this project out of a network location. When we moved the project to C drive worked fine.

Thanks for the help!!
Reply all
Reply to author
Forward
0 new messages