如何检查与mongodb的连接 [英] How to check connection to mongodb
本文介绍了如何检查与mongodb的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用MongoDB
驱动程序连接到数据库.加载表单时,我想设置连接并检查连接是否正常.我是这样的:
I use MongoDB
drivers to connect to the database. When my form loads, I want to set up connection and to check whether it is ok or not. I do it like this:
var connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("reestr");
但是我不知道如何检查连接.我试图将此代码与try-catch
重叠,但无济于事.即使我输入了不正确的connectionString,也仍然无法收到任何错误消息.
But I do not know how to check connection. I tried to overlap this code with try-catch
, but to no avail. Even if I make an incorrect connectionString, I still can not get any error message.
推荐答案
有一个
这篇关于如何检查与mongodb的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文