2 / 2
Nov 2024

I can connect to monogo with username and password but when i try to run the command db.getUsers() I get the below error

MongoServerError[Unauthorized]: not authorized on test to execute command { usersInfo: 1, lsid: { id: UUID(“b017691c-9b78-411b-918f-f134c82000ed”) }, $db: “test” }

I am trying to create a user with read and write role access to keep in my dotnet project to insert and read data in mongo as the issue is suddenly I started getting the below error

MongoDB.Driver.MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1.
—> MongoDB.Driver.MongoCommandException: Command saslStart failed: Authentication failed.

I have created two databases and only one user everything was working fine I was able to to post or fetch something in Mongo but randomly one database started throwing authentication error but it works perfectly with the other database and same connection string

Hi, @Sandeep_Pradhan,

Welcome to the MongoDB Community Forums. I understand that you are getting occasional auth errors when using the MongoDB .NET/C# Driver. The exception message that you are receiving indicates that the credentials are incorrect. This could be the username, password, or auth database for SCRAM-SHA-1. Try including authSource=admin in your connection string. For example:

mongodb://user:pwd@host/?authSource=admin

I would also suggest verifying the connection string using mongosh. If mongosh cannot connect either, then you’ve got a connection string or connectivity problem and not a .NET/C# Driver related problem.

Sincerely,
James