0

I am trying to connect to a MongoDB with my .NET Core 2 controller and I am getting the following error:

MongoDB.Driver.MongoConfigurationException: The connection string 'mongodb://@myapp-a1yri.mongodb.net' is not valid.

I am trying to initialize a MongoClient using the connection string, but I am not sure how to format the connection string and the MongoDB documentation doesn't have anything examples for .NET in it.

This is my current connection string attempt: var client = new MongoClient("mongodb://@myapp-a1yri.mongodb.net");

I am sure it is just simple syntax.

I appreciate the help

7
  • 1
    Why is there an @ sign in connection string? Also you may try adding the port in the connection string. Commented Feb 13, 2018 at 5:49
  • 1
    See also: docs.mongodb.com/manual/reference/connection-string Commented Feb 13, 2018 at 5:52
  • @Corak the only parameter it says is required is the host, that's all I need, correct? Where do I find what the exact entry for the host is? Commented Feb 13, 2018 at 5:54
  • @imlokesh I am not sure, I saw that link somewhere in my CP so I copy and pasted it Commented Feb 13, 2018 at 5:54
  • @blubberbo - shouldn't you know where you host the DB. Also, the @ seems to be the end of the username:password@ parameters which you are missing (if needed). Just copy/paste something from somewhere rarely works exactly as one intends. Commented Feb 13, 2018 at 6:00

1 Answer 1

3

I think your @ sign is causing the problem. Please remove the @ sign from connection string and then try.

var client = new MongoClient("mongodb://myapp-a1yri.mongodb.net")

As I am using without @ sign and it is working fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the information! It got further now, although now I am getting: An exceptionoccurred while opening a connection to the server. ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: Device not configured

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.