问题描述
我有一个SSIS包连接,该连接通过UNC路径连接到Sharepoint站点,如下所示:
\\[Site URL]\DavWWWRoot\sites\DTS_BURM\DARBenchmarks\FileName.csv
我的程序包读取文件并将其导入sql DB。此过程在VS中工作正常。但是,如果我想在作业中从sql Server代理运行程序包,它将为我提供以下错误:
导入RAW数据:错误:无法打开数据文件“ [站点URL] \ DavWWWRoot \ sites \ DTS_BURM \ DARBenchmarks \ FileName.csv”。
最初,这对我来说似乎很明显。运行sql作业的帐户无权访问SharePoint。因此,我在“凭据”文件夹中添加了一个“服务帐户”,然后使用这些凭据为sql Server代理创建代理。另外,我将该服务帐户作为所有者添加到SharePoint中,因此它具有读/写权限。
即使如此,我仍然收到一条错误消息,指出“无法打开数据文件”。我不确定我还能做什么,如果有人有建议,将不胜感激。
解决方法
如我的评论中所述,将SharePoint UNC与SSIS一起使用时,将其部署到服务器时并没有很多运气或稳定性。我们最终在代理作业步骤中使用PowerShell脚本在SSIS步骤之前下载本地文件。
由于代理使用的PowerShell版本以及需要安装SharePoint模块,因此这仅在SQL Server 2014或更高版本上有效。
- 您将需要具有SQL Server的管理员权限,或由管理它的任何人登录并以管理员身份运行PowerShell。
- 然后在任何提示符下以“是”运行以下命令:
安装模块SharePointPnPPowerShellOnline
- 如果在连接关闭或无法通信的情况下运行该命令时出错,则可能与PowerShell中未启用的Tls12有关。运行以下命令以启用Tls12协议:
[Net.ServicePointManager] :: SecurityProtocol = [Net.SecurityProtocolType] :: Tls12
- 然后再次重新运行“安装模块SharePointPnPPowerShellOnline”,它现在应该成功。
完成此操作后,我们将为此专门设置一个服务帐户,并发现该帐户必须与您要从中下载文件的SharePoint网站的“网站所有者”组分开。
然后使用以下代码添加PowerShell Agent Job步骤,以下载SSIS的本地文件。针对您的环境进行更新。
$SharepointBaseURL = "https://yoursharepoint.com/sites/sitename/" #base URL of your site
$SharepointDocumentFolder = "Shared Documents/path to folder" #path to the folder where the files are located
$LocalShare = "\\server\localshare" #where you download local,sql proxy account needs access
$un = "YourAccount@domain.com"
$pw = "Password"
Set-Location "c:\" #we had to have this when running in agent job
try
{
$sp = $pw | ConvertTo-SecureString -AsPlainText -Force
$plainCred = New-Object system.management.automation.pscredential -ArgumentList $un,$sp
Connect-PnPOnline -Url $SharepointBaseURL -Credentials $plainCred -ErrorAction Stop
$SharePointFileList = Get-PnPFolderItem -FolderSiteRelativeUrl $SharepointDocumentFolder -ItemType File #gets a list of all files in the sharepoint directory
foreach ($File in $SharePointFileList)
{
Get-PnPFile -Url $File.ServerRelativeUrl -Path $LocalShare -Filename $File.Name -AsFile -ErrorAction Stop #Add "-Force" parameter if you want to override if the file already exists
}
}
Catch
{
Throw $_.Exception.Message #any errors/exceptions this bubbles it out into job history
}
然后从那里配置SSIS以访问本地文件。