give IT a try

プログラミング、リモートワーク、田舎暮らし、音楽、etc.

SSISからExcelを読み込む方法

技術メモです。
SSIS(SQL Server Integration Services)でExcelを読み込む場合、クライアントではうまく動作してもサーバーにデプロイすると、エラーが出て動作しない場合があります。
そんなときは以下のような問題があるかも。

  • 64bit版SQL Serverではうまく動かないとのことなので、強制的に32bit版DTExec.exeを使って起動させる。たとえばxp_cmdshellを使って実行させる場合はこんな感じ。
exec xp_cmdshell 'C:\Progra~2\Micros~2\90\DTS\Binn\DTExec.exe /DTS "\MSDB\(SSISパッケージ名)" /SERVER (サーバー名) /DECRYPT (パスワード) /MAXCONCURRENT " -1 " /CHECKPOINTING OFF  /REPORTING V'

  • DTExec.exeまでのパスにスペースが入ると動かないみたいなので、「C:\Progra~2\Micros~2」のように書くあたりがミソです。
  • あと、xp_cmdshellを使うときはProxy Account関連の設定も重要になるみたいです。つまり実行アカウントの権限によってはうまくファイルにアクセスできない場合もあります。ただ、SQL Server 2005のProxy Accountに関する知識はあまり豊富ではないので、別途他のサイトを参考にしてみてください (^ ^;

2010.02.05 追記
Test用サーバーで動かすと以下のようなエラーが発生しました。

Error: 2010-02-04 20:33:45.53
   Code: 0xC0202009
   Source: XXX
   Description: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available.  Source: "Microsoft JET Database Engine"  Hresult: 0x80004005  Description: "Unspecified error".
End Error


色々調べた結果下記のディレクトリが存在しないのが原因でした。

C:\Documents and Settings\(実行アカウント名)\Local Settings\Temp


またxp_cmshellから実行している場合はプロキシアカウントが上記のフォルダに対するRead/Write権を持つ必要があります。


<参考URL>
http://support.microsoft.com/kb/933835


非常に分かりにくいトラブルなので、みなさんご注意を・・・。


2010.05.11追記

SQL Serverにデフォルトインスタンスが設定されていないと、以下のようなエラーが発生する場合があります。

Microsoft (R) SQL Server Execute Package Utility
Version 9.00.4035.00 for 32-bit
Copyright (C) Microsoft Corp 1984-2005. All rights reserved.
NULL
Started:  10:29:33
Could not load package "\XXX" because of error 0x80131500.
Description: The SQL server specified in SSIS service configuration is not present or is not available. This might occur when there is no default instance of SQL Server on the computer. For more information, see the topic "Configuring the Integration Services Service" in Server 2005 Books Online.
NULL
Login timeout expired
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.
Named Pipes Provider: Could not open a connection to SQL Server [2]. 
Source: MsDtsSrvr
Started:  10:29:33
Finished: 10:29:49
Elapsed:  15.656 seconds
NULL



この場合はSQL Serverに対してデフォルトインスタンスの設定が必要です。
詳細は以下のページに載っています。


http://msdn.microsoft.com/ja-jp/library/ms137789.aspx


それにしても何でこんなにややこしいでしょうね?SSISって。
もっとシンプルな設計にはできなかったんでしょうか・・・。