如何在客户端调用SQLSERVER的DTS包(并且可以输入参数)?
2024-07-21 02:08:17
供稿:网友
**********************************************************
author:黄山光明顶
mail:[email protected]
version:1.0.0
date:2004-1-30
(如需转载,请注明出处!,如果有问题请发mail给我:-))
***********************************************************
经常有网友问起如何在客户端调用sqlserver服务器端的一些脚本和对象,并且可以输入参数,我就举例说明一下如何在客户端调用sqlserver的dts包,并且可以输入参数,并且可以记录日志:
测试环境:
服务器:piii866+512mb +raid5
windows 2000 server+sp4 ;sqlserver2000+sp3
客户端:windows 2000 pro+sp4+sqlserver2000 client+sp3
1.先在server端建立一个dts包:
这可以根据向导一步一步的完成,我就不多说了。比如我门建立了一个导入excel文件到sqlserver的dts包:dts_exceltosqlserver
2.在客户端建立一个批处理文件
crundts.bat
3.用文本编辑器编辑:
@@echo off
if [%1] == [] goto usage
if [%2] == [] goto usage
if [%3] == [] goto usage
if [%4] == [] goto usage
cls
set logfile=c:/dtsrun.log
echo %time% manual dts package start run......... >> %logfile%
echo ------------------------------------------ >> %logfile%
@dtsrun /s %1 /u %2 /p %3 /n %4 >> %logfile%
if errorlevel 1 goto error
echo %time% manual dts package end......... >> %logfile%
echo ------------------------------------------ >> %logfile%
pause
goto finish
:error
echo ------------------------------------------- >> %logfile%
echo dtsrun error pls check log .........
echo %time% globalstore backup abnormal end. >> %logfile%
pause
goto finish
:usage
echo.
echo usage:crundts %1 servername %2 use_name %3 password %4 dts_name
:finish
4.保存该文件:
然后你可以在任何程序中调用,也可以手工执行,输入参数
5.测试运行:
在dos提示符下运行:crundts servername sa password dts_exceltosqlserver
6.日志信息:
10:24:29.38 manual dts package start run.........
------------------------------------------
dtsrun: loading...
error: -2147217900 (80040e14); provider error: 14262 (37b6)
error string:
error source:
help file:
help context: 0
10:24:29.66 manual dts package end.........
------------------------------------------
10:27:29.41 manual dts package start run.........
------------------------------------------
dtsrun: loading...
dtsrun: executing...
dtsrun onstart: dtsstep_dtsdatapumptask_1
dtsrun onprogress: dtsstep_dtsdatapumptask_1; 23 rows have been transformed or copied.; percentcomplete = 0; progresscount = 23
dtsrun onfinish: dtsstep_dtsdatapumptask_1
dtsrun: package execution complete.
10:27:30.02 manual dts package end.........
------------------------------------------