我正在使用以下测试代码并收到错误(显示在代码中)。我的连接字符串应该设置为什么?
我正在使用Quartz.Impl.MongoDB 1.2,Quartz 2.1.2.400,MongoDB.Bson 1.9.2.235和MongoDB.Driver 1.9.2.235
我已经尝试将连接字符串设置为“server = mongodb:// localhost; database = quartznet;”
class Program
{
static void Main(string[] args)
{
// test that the local mongodb is working
var connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("quartznet");
var collection = database.GetCollection<Entity>("entities");
var entity = new Entity { Name = "Tom" };
collection.Insert(entity);
var id = entity.Id;
// local mongodb is working. Now try to set up a Quartz Scheduler
var properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "MyApplicationScheduler"; // needed if you plan to use the same database for many schedulers
properties["quartz.scheduler.instanceId"] = System.Environment.MachineName + DateTime.UtcNow.Ticks; // requires uniqueness
properties["quartz.jobStore.type"] = "Quartz.Impl.MongoDB.JobStore, Quartz.Impl.MongoDB";
/*
* From the App.Config
<connectionStrings>
<add name="quartznet-mongodb" connectionString="server=localhost;database=quartznet;" />
</connectionStrings>
*/
var scheduler = new Quartz.Impl.StdSchedulerFactory(properties).GetScheduler(); // error thrown on this line:
// Inner exception: Invalid connection string 'server=localhost;database=quartznet;'.
Console.ReadLine();
}
}
public class Entity
{
public ObjectId Id { get; set; }
public string Name { get; set; }
}
答案 0 :(得分:2)
答案是:“mongodb:// localhost / quartznet”