本文整理汇总了C#中MongoDB.Driver.MongoClient.DatabaseExists方法的典型用法代码示例。如果您正苦于以下问题:C# MongoClient.DatabaseExists方法的具体用法?C# MongoClient.DatabaseExists怎么用?C# MongoClient.DatabaseExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.MongoClient
的用法示例。
在下文中一共展示了MongoClient.DatabaseExists方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckMongoDbConnection
public static ActionResult CheckMongoDbConnection(Session session)
{
session.Log("Start: CheckMongoDbConnection.");
session["MONGODB_CONNECTION_ESTABLISHED"] = "1";
try
{
string hostName = GetPropertyStringValue(session, "MONGO_HOST");
if (string.IsNullOrEmpty(hostName))
{
throw new Exception("Host name is empty. Please enter a correct value.");
}
string databaseName = GetPropertyStringValue(session, "MONGO_DATABASE");
if (string.IsNullOrEmpty(databaseName))
{
throw new Exception("Database name is empty. Please enter a correct value.");
}
string connectionString = GetPropertyStringValue(session, "DATABASE_CONNECTION_STRING");
session.Log("Connection string to MongoDB: {0}", connectionString);
var mongoDb = new MongoClient(connectionString).GetServer();
var databaseExists = mongoDb.DatabaseExists(databaseName);
session.Log("Database {0} {1} exist.", databaseName, databaseExists ? "already" : "does not");
}
catch (Exception e)
{
InitializeMessageBox(session, e.Message, ERROR_MESSAGE);
session.Log("Error: {0}; {1};", e.Message, e.StackTrace);
session["MONGODB_CONNECTION_ESTABLISHED"] = "0";
}
session.Log("Finish: CheckMongoDbConnection.");
return ActionResult.Success;
}