經常有網友問起如何在客戶端調用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.........