教你如何在客户端调用SQLServer的DTS包

来源:岁月联盟 编辑:zhuzhu 时间:2007-08-08

经常有网友问起如何在客户端调用SQLSERVER服务器端的一些脚本和对象,并且可以输入参数,我举例说明一下如何在客户端调用SQLSERVER的DTS包,并且可以输入参数,并且可以记录日志:

 

测试环境:服务器:PIII866 512MB RAID5WINDOWS 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 offif [%1] == [] goto Usageif [%2] == [] goto Usageif [%3] == [] goto Usageif [%4] == [] goto UsageclsSET LOGFILE=c:/DTSRUN.LOGecho %TIME% Manual DTS package start run......... >> %LOGFILE%echo -------------->> %LOGFILE%@dtsrun /S %1 /U %2 /P %3 /N %4 >> %LOGFILE%if errorlevel 1 goto Errorecho %TIME% Manual DTS package end..>> %LOGFILE%echo --------------- >> %LOGFILE%PAUSEgoto FINISH:Errorecho --------------->> %LOGFILE%echo DTSRUN ERROR PLS CHECK LOG .........echo %TIME% GlobalStore Backup abnormal end. >> %LOGFILE%pausegoto FINISH:Usageecho.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...--------------------------------: Loading... Error: -2147217900 (80040E14); Provider Error: 14262 (37B6)Error string: Error source: Help file: Help context: 010:24:29.66 Manual DTS package end......... ------------------------10:27:29.41 Manual DTS package start run....----------------------------DTSRun: Loading...DTSRun: Executing...DTSRun OnStart: DTSStep_DTSDataPumpTask_1DTSRun OnProgress: DTSStep_DTSDataPumpTask_1; 23 Rows have been transformed or copied.; PercentComplete = 0; ProgressCount = 23DTSRun OnFinish: DTSStep_DTSDataPumpTask_1DTSRun: Package execution complete.10:27:30.02 Manual DTS package end......---------------------------------