1

SQLスクリプトから7-zipを呼び出すことは可能ですか? 基本的に、テーブルをcsvに抽出してから、それらを7zファイルにパッケージ化しています。SQL Server がインストールされているマシンに 7-zip をインストールしてパスに追加しましたが、これでは十分ではないようです。

xp_cmdshell でスクリプトを実行しようとすると、次のエラーが表示されます

'7z' is not recognized as an internal or external command,
operable program or batch file.

これはコードです、私はすでに変数を宣言しています

declare @archiveCommand nvarchar(max)
declare @filename nvarchar(max)

set @archiveCommand = '7z a '+@filename+'.7z '+@filename+' '
print @archiveCommand
EXEC master..xp_cmdshell @archiveCommand
4

2 に答える 2

4

これが今役立つかどうかはわかりませんが、この問題に遭遇し、ファイル名で 7z アプリを呼び出して解決しました。

したがって、代わりに:

set @archiveCommand = '7z a '+@filename+'.7z '+@filename+' '

あなたが望むでしょう:

set @archiveCommand = '"C:\Program Files\7-zip\7z" a '+@filename+'.7z '+@filename+' '

于 2011-04-04T11:34:20.287 に答える
2

It's possible, yes, but probably a bad idea: permissions are often a problem (as you've found out), paths and working directories will trip you up, and building shell commands in SQL is a pain all round. It would be much easier just to use an external script, and run it from a scheduled job or SSIS package.

If you clarify exaclty why and when you want to run the script from SQL then someone may be able to suggest a better approach. I do exactly the same thing using SSIS and Python, for example.

于 2010-09-14T14:54:04.473 に答える