1
我已经开始使用MongoDB .Net driver将WPF应用程序连接到MongoLabs上托管的MongoDB数据库。如何在MongoDB连接期间解决System.TimeoutException?
但是,我创建加载连接(在MainViewModel的构造函数上调用)创建以下方法,在下面的方法中标记的行上抛出超时异常。
我试图通过添加一个类型为MongoException的异常检查来解决错误没有用。还检查连接字符串是有效的按照该文档,似乎这样:(密码出演出于安全)
private const string connectionString = "mongodb://<brianVarley>:<********>@ds048878.mongolab.com:48878/orders";
引发的特定错误如下:
An exception of type 'System.TimeoutException' occurred in mscorlib.dll
完全错误链接: http://hastebin.com/funanodufa.tex
有没有人知道我为什么我的连接方法超时的原因?
public List<Customer> LoadCustomers()
{
var client = new MongoClient(connectionString);
var database = client.GetDatabase("orders");
//Get a handle on the customers collection:
var collection = database.GetCollection<Customer>("customers");
try
{
//Timeout error thrown at this line:
customers = collection.Find(new BsonDocument()).ToListAsync().GetAwaiter().GetResult();
}
catch(MongoException ex)
{
//Log exception here:
MessageBox.Show("A handled exception just occurred: " + ex.Message, "Connection Exception", MessageBoxButton.OK, MessageBoxImage.Warning);
}
return customers;
}
您是否尝试过通过蒙戈外壳或其他方法连接,以确定它是否是一个服务器的问题,而不是你的代码? – womp
不,实际上好的建议,现在会给我一个去吧 –
我认为你的蒙哥拉布凭证是无效的。几周前我有同样的问题。您是否为数据库创建了用户,或者您是否可以使用您的mongolab帐户的凭据? –