如何在客户端调用SQLSERVER的DTS包(并且可以输入参数)?

发表于:2007-06-08来源:作者:点击数: 标签:
********************************************************** Author:黄山光明顶 mail:leimin@jxfw.com version:1.0.0 date:2004-1-30 (如需转载,请注明出处!,如果有问题请发MAIL给我:-)) *********************************************************** 经

**********************************************************

Author:黄山光明顶

mail:leimin@jxfw.com

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.........          
------------------------------------------ 

 

 

原文转自:http://www.ltesting.net