c# driver - "Connection Requires Credentials" when calling Server.GetLastError()

320 views
Skip to first unread message

Sam Martin

unread,
Feb 12, 2012, 9:28:58 AM2/12/12
to mongod...@googlegroups.com
Hi all,

This must be something I'm doing wrong as I can't find any other examples of the error.

When creating a server object using a URI containing a username, password and database, e.g.
var server = MongoServer.Create("mongo://User:pass...@1234.mongolab.com/dbname")

Then a db object,
var db = server.GetDatabase("dbname")

.... Then Perform some updates....

Then server.GetLastError() raises an invalid operation exception, message = "Connection Requires Credentials".

It all works fine locally without cress in uri.

Anyone experiences this or can see what I'm doing wrong?

Thanks in advance

Sam

Robert Stam

unread,
Feb 12, 2012, 9:45:55 AM2/12/12
to mongod...@googlegroups.com
Can you show a bit more of your code?

Are you using RequestStart?

What version of the C# driver are you using?

Can you provide a full stack trace? (You can remove the part of the stack trace that is in your application if you wish).


Sam

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-user/-/UcAshi0sAasJ.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Robert Stam

unread,
Feb 12, 2012, 10:00:31 AM2/12/12
to mongod...@googlegroups.com
I can reproduce this on my machine using version 2.0.2 of the server. The problem is that the GetLastError command is sent to the admin database, but in this scenario the provided credentials are only valid for the "dbname" database. I'm not sure yet if this is a bug that's been in the C# driver all along or if there has been a change in the server that has caused this to start happening.

What version(s) of the server have you seen this happen on?

Have you tried using SafeMode.True? It's easier than calling GetLastError yourself and might work better.

Robert Stam

unread,
Feb 12, 2012, 10:16:38 AM2/12/12
to mongod...@googlegroups.com
Stepping through the code it's starting to look like this is an issue in the driver, not the server. But it's going to take me awhile to figure out what to do about it, so in the meantime your best bet is to use SafeMode.True instead of calling GetLastError yourself if possible.

Sam Martin

unread,
Feb 12, 2012, 10:17:19 AM2/12/12
to mongodb-user
hi robert,

here sample, by the looks of it too late

Server= MongoServer.Create("mongodb://
u:p...@accno.mongolab.com:accno/dbname");
            Db= Server.GetDatabase("dbname");
            using (var req = Server.RequestStart(Db))
            {
                var col = Db.GetCollection("testcol");
                col.Insert(new { prop = "value" });
                var lastError = Server.GetLastError();
            }

Server is 2.0.2, using the most up-to-date c# driver.

Haven't tried safemode=true, but will look now.

Thanks,
Sam

On Feb 12, 3:00 pm, Robert Stam <rob...@10gen.com> wrote:
> I can reproduce this on my machine using version 2.0.2 of the server. The
> problem is that the GetLastError command is sent to the admin database, but
> in this scenario the provided credentials are only valid for the "dbname"
> database. I'm not sure yet if this is a bug that's been in the C# driver
> all along or if there has been a change in the server that has caused this
> to start happening.
>
> What version(s) of the server have you seen this happen on?
>
> Have you tried using SafeMode.True? It's easier than calling GetLastError
> yourself and might work better.
>
>
>
>
>
>
>
> On Sun, Feb 12, 2012 at 9:45 AM, Robert Stam <rob...@10gen.com> wrote:
> > Can you show a bit more of your code?
>
> > Are you using RequestStart?
>
> > What version of the C# driver are you using?
>
> > Can you provide a full stack trace? (You can remove the part of the stack
> > trace that is in your application if you wish).
>
> > On Sun, Feb 12, 2012 at 9:28 AM, Sam Martin <sambomar...@gmail.com> wrote:
>
> >> Hi all,
>
> >> This must be something I'm doing wrong as I can't find any other examples
> >> of the error.
>
> >> When creating a server object using a URI containing a username, password
> >> and database, e.g.
> >> var server = MongoServer.Create("mongo://
> >> User:passw...@1234.mongolab.com/dbname")

Sam Martin

unread,
Feb 12, 2012, 10:22:58 AM2/12/12
to mongodb-user
Hi Robert,

Yes, update with SafeMode.True worked as expected.

Leave it with you on the GetLastError() problem, but I'm good for now.

Thanks for your help.

Sam

Robert Stam

unread,
Feb 12, 2012, 12:25:31 PM2/12/12
to mongod...@googlegroups.com
Glad to help.

For anyone wanting to call GetLastError explicitly when authentication is on, you can watch:

Reply all
Reply to author
Forward
0 new messages