我目前正在尝试使用 RavenDB (3.0) 并尝试使用批量插入功能。但是,尽管批量插入似乎可以工作,但在完成后我不断收到异常:
An exception of type 'System.IO.EndOfStreamException' occurred in Raven.Client.Lightweight.dll but was not handled in user code
Additional information: Attempted to read past the end of the stream.
堆栈跟踪是
at Raven.Client.Connection.ObservableLineStream.<Start>b__1(Task`1 task) in c:\Builds\RavenDB-Stable-3.0\Raven.Client.Lightweight\Connection\ObservableLineStream.cs:line 39
at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
这是我的代码:
static void Main(string[] args)
{
try
{
using (var store = new DocumentStore {
Url = "http://localhost:8080/",
DefaultDatabase = "Northwind" })
{
store.Initialize();
int total = 10000;
using (var bulkInsert = store.BulkInsert())
{
for (int i = 0; i < total; i++){
bulkInsert.Store(new Employee{
FirstName = "FirstName #" + i,
LastName = "LastName #" + i});
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.ReadLine();
}
}
奇怪的是数据正在写入数据库(我可以在数据库浏览器中查看),而且我的代码中没有捕获到异常——它被标记为未处理,尽管try/catch
.
我对它为什么会发生感到困惑,更重要的是,我如何防止它。有人有想法么?