【发布时间】:2020-04-29 11:44:46
【问题描述】:
我想创建一个脚本任务来将数据从 MongoDB 加载到 SQL Server。
我使用的是 Visual Studio 2017,目标 SQL Server 版本是 2017。
基于上面的脚本任务的默认目标.NET版本是4.5,所以我得到了2.3版本,这是最新的目标4.5
为了获取dll,我首先使用NuGet下载了包,然后复制了以下dll:
MongoDB.Driver.dll
MongoDB.Driver.Core.dll
MongoDB.Bson.dll
我按照此处的说明进行操作: http://codeingaddiction.blogspot.com/2011/06/how-to-add-strong-name-to-existing-dll_16.html
为了生成强命名的dll。
最后,我将 GAC 上的 dll 添加到以下路径
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools
然后我创建了一个脚本任务并手动添加了 3 个 dll。
我的测试代码如下:
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Core;
using MongoDB.Bson.Serialization;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
public override void PreExecute()
{
base.PreExecute();
}
public override void PostExecute()
{
base.PostExecute();
}
public override void CreateNewOutputRows()
{
MongoClient client = new MongoClient("mongodb://dgm-mongodbdev-01.development.dc.opap:27017");
IMongoDatabase database = client.GetDatabase("sportsbetting-staging");
IMongoCollection<BsonDocument> collection = database.GetCollection<BsonDocument>("event");
collection.Find<BsonDocument>(null).Limit(3);
Console.WriteLine(collection);
}
}
尝试构建会出现以下错误:
Severity Code Description Project File Line Suppression State
Error The type 'IAsyncCursorSource<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'MongoDB.Driver.Core, Version=2.3.0.157, Culture=neutral, PublicKeyToken=null'.
MongoDb 核心驱动程序没有我可能遗漏的任何其他依赖项。对于 4.5 版本的 .NET,唯一的依赖项是 MongoDB.Bson,它作为参考添加。
我找到的关于 SSIS 脚本任务的唯一文章是: https://arcanecode.com/2014/01/14/importing-mongodb-data-using-ssis-2012/
已过时,因为它使用的是 1.x 版驱动程序。
有什么想法吗?该消息似乎具有误导性,因为很明显我没有遗漏任何依赖项。
【问题讨论】:
-
我发现使用外部引用时使用控制台应用程序更容易。检查它是否在那里工作。
标签: c# ssis mongodb-query