背景情報: いくつか (現在 9 つ) のコア SSRS レポートを実行しています。これらはかなりパラメータ化されていますが、重要なのは StartDate、EndDate、Department です。これらは、日次、週次、月次、四半期、年次、アドホック(インタラクティブ)ベースで実行されます。自動化されたレポートは、Sharepoint の特定のフォルダーに保存されます。
これまでに行ったこと: すべてのレポートを、パラメーターを「待機」せず、同じ 3 つのパラメーターのみでレポートを生成するような形式にしました。したがって、これらは URL だけで呼び出すことができます。
http://server/ReportServer?/Folder/Report1&Department=DEPT1&ContactFromDate=01/01/2012&ContactToDate=31/01/2012+23:59:59&rs:Command=Render&rs:Format=PDF
http://server/ReportServer?/Folder/Report5&Department=DEPT8&ContactFromDate=01/04/2012&ContactToDate=06/01/2012+23:59:59&rs:Command=Render&rs:Format=PDF
..等々。
約 20 の部門があり、5 つのレポート タイプのそれぞれを必要としているため、サブスクリプションを設定することは実際にはオプションではなく、SSIS の出番です。
基本的に SQL テーブルからレポートのタイトルと部門を読み取り、部門/レポートごとに ADO.Net 列挙子を設定し、ネストされた For..Each ループを実行し、WebRequest を起動して結果の PDF を保存しようとするパッケージを作成しました。共有ポイント フォルダー。これは私の開発者用 PC では正常に動作しますが、SQL Server でジョブとして実行すると (SQL Server で設定されたプロキシ経由で)、「ネットワーク名が見つかりません」というエラーで失敗します。
これは私のVisual Basicコードです:
//Microsoft SQL Server Integration Services Script Task
//Write scripts using Microsoft Visual Basic
//The ScriptMain class is the entry point of the Script Task.
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.ComponentModel
Imports System.Diagnostics
<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Protected Sub SaveFile(ByVal url As String, ByVal localpath As String)
Dim loRequest As System.Net.HttpWebRequest
Dim loResponse As System.Net.HttpWebResponse
Dim loResponseStream As System.IO.Stream
Dim loFileStream As New System.IO.FileStream(localpath, System.IO.FileMode.Create, System.IO.FileAccess.Write)
Dim laBytes(256) As Byte
Dim liCount As Integer = 1
Try
loRequest = CType(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
loRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
loRequest.ImpersonationLevel = Security.Principal.TokenImpersonationLevel.Impersonation
loRequest.Timeout = 600000
loRequest.Method = "GET"
loResponse = CType(loRequest.GetResponse, System.Net.HttpWebResponse)
loResponseStream = loResponse.GetResponseStream
Do While liCount > 0
liCount = loResponseStream.Read(laBytes, 0, 256)
loFileStream.Write(laBytes, 0, liCount)
Loop
loFileStream.Flush()
loFileStream.Close()
Catch ex As Exception
End Try
System.Threading.Thread.Sleep(2000)
End Sub
Public Sub Main()
Dim strUrl, strUrlSP, strDestination As String
--New destination for monthly
strDestination = Dts.Variables("varDestinationPathSP").Value.ToString + "\" + Dts.Variables("varDepartmentName").Value.ToString + "\Monthly\" + Dts.Variables("varCrmReportTitles").Value.ToString + " " + Format(Now, "yyyyMM") + ".pdf"
--New Url for Monthly reports.
strUrl = "http://server/ReportServer?/Scheduled+Reporting/" + Dts.Variables("varCrmReportTitles").Value.ToString + "&Department=" + Dts.Variables("varDepartmentCode").Value.ToString + "&ContactFromDate=" + Format(Dts.Variables("varDatPreviousMonthStart").Value, "dd/MMM/yyyy").ToString + "&ContactToDate=" + Format(Dts.Variables("varDatPreviousMonthEnd").Value, "dd/MMM/yyyy").ToString + "+23:59:59&rs:Command=Render&rs:Format=PDF"
strUrlSP = "http://intranet/ProjectBusinessSystems/ContactManagement/DocumentLibrary/Forms/AllItems.aspx?RootFolder=/ProjectBusinessSystems/ContactManagement/DocumentLibrary/Scheduled+Reports/" + Dts.Variables("varDepartmentName").Value.ToString + "/Monthly"
strUrl = fnPadSpaces(strUrl)
strUrlSP = fnPadSpaces(strUrlSP)
--Set up the file path so the next step can copy to local drive (Testing purposes only)
Dts.Variables("varFullReportPathToCopy").Value = strDestination
Dts.Variables("varDestinationURL").Value = strUrlSP
SaveFile(strUrl, strDestination)
Dts.TaskResult = ScriptResults.Success
End Sub
Public Function fnPadSpaces(ByVal StringToEncode As String, Optional ByVal UsePlusRatherThanHexForSpace As Boolean = True) As String
Dim TempAns As String
Dim CurChr As Integer
CurChr = 1
TempAns = ""
Do Until CurChr - 1 = Len(StringToEncode)
Select Case Asc(Mid(StringToEncode, CurChr, 1))
Case 32 -- Replace Spaces
If UsePlusRatherThanHexForSpace = True Then
TempAns = TempAns & "+"
Else
TempAns = TempAns & "%" & Hex(32)
End If
Case Else -- Otherwise pass it through
TempAns = TempAns & Mid(StringToEncode, CurChr, 1)
End Select
CurChr = CurChr + 1
Loop
fnPadSpaces = TempAns
End Function
End Class
PDF を生成したが、sharepoint フォルダーへの書き込みに失敗した場合、SaveFile(strUrl, strDestination) 行で失敗します。インフラストラクチャ担当者は、SSIS ジョブを実行しているアカウントがフォルダーに書き込むことができるようにアクセス許可が設定されていることを保証します。また、開発ボックスの Vis Studio でジョブを実行すると、常に機能します。
varDestinationPath は次のようになります。
\\sharepoint\ProjectBusinessSystems\ContactManagement\DocumentLibrary\Some Reports
ここで、sharepoint はエイリアスではなくサーバー名です。
ログ ファイル ビューアーからの実際の (非常に詳細な) エラー メッセージを以下に示します。
Date 06/06/2012 13:52:30
Log Job History (Scheduled Reports MONTHLY)
Step ID 1
Server DevServer
Job Name Scheduled Reports MONTHLY
Step Name Run Package
Duration 00:00:04
Sql Severity 0
Sql Message ID 0
Operator Emailed
Operator Net sent
Operator Paged
Retries Attempted 0
Message
Executed as user: WinFarm\crmreporter. Microsoft (R) SQL Server Execute Package Utility Version 10.50.2500.0 for 64-bit Copyright (C) Microsoft Corporation 2010. All rights reserved. Started: 13:52:31 Error: 2012-06-06 13:52:34.46 Code: 0x00000001 Source: Script Task - Render Report Description: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.IOException: The network name cannot be found. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at ScriptTask_f689e2ad4d3f481a87e3678e2d746c39.vbproj.ScriptMain.SaveFile(String url, String localpath) at ScriptTask_f689e2ad4d3f481a87e3678e2d746c39.vbproj.ScriptMain.Main() --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript() End Error DTExec: The package execution returned DTSER_FAILURE (1). Started: 13:52:31 Finished: 13:52:34 Elapsed: 3.183 seconds. The package execution failed. The step failed.
私が間違っていること、または何をしようとしているのか、何か考えはありますか? さらに情報を提供する必要がある場合は、質問してください。返信します。スクリプトは 99% 完了していると確信していますが、サーバーの資格情報/権限の問題で失敗するだけだと思います。:/
更新: コードがローカル エリア (C:\Temp) に書き込まれ、ネットワーク共有上のフォルダー (\someserver\some フォルダーにスペースが含まれる \etc) にも書き込まれることを確認できるため、問題は多少シフトされます。 sharepoint フォルダーへの書き込み。SSRS をネイティブ モードで実行していますが、プロキシ経由で実行されている SQL Server エージェント ジョブから共有ポイント フォルダーに書き込むときに、「ネットワーク パスが見つかりません」というエラーが発生する原因について何か考えがある人はいますか?
また、ファイル システム タスクを介してファイルを移動しようとしましたが、これでも失敗します。:(問題が何であるかについてのアイデアはありますか?
バンプ。ここで私自身の質問に答える可能性がありますが、いくつかの調査の結果、Sharepoint を参照している Win2008 サーバーが WebClient サービスを実行していないことがわかりました。これは、WebDAV がインストールされていないため、共有ポイント ライブラリをネットワーク パスとして「認識」できない (またはドライブをネットワーク パスにマップできない) ことを意味します。これらのコンポーネントをインストールして報告します。しかし、誰かがこれについてさらに情報を持っているなら、それはありがたいです! 夜、迷路に迷い込んだ目の見えない男のようだ。:)