连接到从ASP.NET远程MongoDB实例 [英] Connect to remote MongoDB instance from ASP.NET
问题描述
我有一些麻烦纳丁为什么我无法连接到我的MongoHQ创建一个新的数据库。
我想包括在我的Web.config文件中正确的连接字符串,并有我的Mongo对象指的是数据库连接。
连接字符串(编辑,很明显)是:
公共访问
蒙戈flame.mongohq.com:27065/dunedin -u {用户名} -p {密码}
AWS内访问
蒙戈flame.local.mongohq.com:27065/dunedin -u {用户名} -p {密码}
很显然,我已经包括了我正确的用户名在密码发生在括号中的占位符。
我的code是:
字符串连接= ConfigurationManager.ConnectionStrings [DBMongo]的ConnectionString。
VAR蒙戈=新蒙戈(连接);
mongo.Connect();
然而,当我尝试实例化的Mongo对象,我得到一个格式异常说
这是无效的连接字符串:
什么是连接字符串应该看起来像远程托管的MongoDB实例?
编辑:
在web.config中的连接字符串项是
<添加名称=DBMongo的connectionString =蒙戈flame.mongohq.com:27065/dunedin -u ausername -p apassword/>
在蒙戈外壳
键入显示用户
。然后使用散列密码,这显示在连接字符串中的密码。
I'm having some trouble nutting out why I'm unable to connect to a new database I've created at MongoHQ.
I want to include the correct connection string in my Web.config file and have my Mongo object refer to that for the database connection.
The connection strings (edited, obviously) are:
Public Access
mongo flame.mongohq.com:27065/dunedin -u {username} -p {password}
AWS Internal Access
mongo flame.local.mongohq.com:27065/dunedin -u {username} -p {password}
Obviously, I've included my correct username in password in place of the placeholders in the braces.
My code is:
string connection = ConfigurationManager.ConnectionStrings["DBMongo"].ConnectionString;
var mongo = new Mongo(connection);
mongo.Connect();
However, as soon as I try to instantiate that Mongo object, I get a format exception saying
Invalid connection string on:
What is that connection string supposed to look like for remotely-hosted MongoDB instances?
EDIT:
The Connection String entry in Web.Config is
<add name="DBMongo" connectionString="mongo flame.mongohq.com:27065/dunedin -u ausername -p apassword"/>
In the mongo shell
, type show users
. Then use the hashed password this displays for your password in the connection string.
这篇关于连接到从ASP.NET远程MongoDB实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!