all groups > sql server programming > april 2004 >
You're in the

sql server programming

group:

Help DTS package


Help DTS package Sivla
4/30/2004 11:05:21 PM
sql server programming:
I need to run a dts package from a command line that accepts a parameter.
then opens a text file on my c: \files folder and reads the contents of the
file into a table in a database

Re: Help DTS package Barry McAuslin
5/1/2004 7:09:51 PM
Create a global variable called "FilePath"

use "/A FilePath:typeid=8 C:\....." as an command line option.
see dtsrun in BOL

Use VBScript in the DTS package like this. (pseudo code)

DTSGlobalVariables.Parent.Connections("ImportFile").DataSource =
DTSGlobalVariables("FilePath").Value

HTH

----------

Barry McAuslin

Look inside your SQL Server files with SQL File Explorer.
Go to http://www.sqlfe.com for more information.

[quoted text, click to view]

Re: Help DTS package Sivla
5/1/2004 11:48:23 PM
where do i create the globle variable?
thanks for your help
[quoted text, click to view]

Re: Help DTS package Dan Guzman
5/2/2004 8:34:01 AM
You can create DTS package global variables from the DTS Package designer
under the Global Variables tab in package properties. In SQL 2000, you can
use a Dynamic Properties task to assign global variable values to specific
properties.

It's a good practice to use global variables for properties that may change
between packages executions, such as file locations and server names.

--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]

Re: Help DTS package Sivla
5/2/2004 10:26:09 PM
i have followed the instructions that you have provided me but i am getting
an error specified server not found. i am testing this on the local machine
so the server is running
here is my dtsrun ececution

dtsrun /S "<TROY>" /U "sa" /P "emachine" /N "FileTransfer" /A
Datainput:Typeid=8 "Data1"



[quoted text, click to view]

Re: Help DTS package Sivla
5/2/2004 10:40:15 PM
I have fixed my problem i was putting <> around the server name.
now my dts runs fine but the VB script that i wrote does not execute how do
i get my DTS package to run my vb Script thanks
[quoted text, click to view]

Re: Help DTS package Dan Guzman
5/3/2004 8:20:46 AM
You can execute your VBScript from a DTS package ActiveX Script Task.
Global variables can be accessed from within your script using the
DTSGlobalVariables collection (e.g. DTSGlobalVariables("FilePath").Value).

--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]

Re: Help DTS package Sivla
5/3/2004 11:10:16 PM
I have a message box on the first line of my dts script
that should display the value that i am passing from the command prompt it
is blank.
below is my command line in put why cant i display my global variable.

dtsrun /S "TROY" /U "sa" /P "emachine" /N "FileTransfer" /A Dtinput:typeid=8
"Data1"


here is my script

'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************

Function Main()
msgbox DTSGlobalVariables("Dtinput").Value

Select case DTSGlobalVariables("Dtinput").Value



Case "Data1"
dim oFSO
dim x
dim mySourceConn
dim mySourceRecordset

' instantiate the Scripting Object
set oFSO = CreateObject("Scripting.FileSystemObject")

' Open the file
set x = oFSO.OpenTextFile("C:\Files\data1.txt")

' store the first line, which is the Start Date, in a global variable
DTSGlobalVariables("txtInput").Value = x.Readall
MsgBox "This files reads: " & DTSGlobalVariables("txtInput").Value

' Instantiate the ADO objects.
set mySourceConn = CreateObject("ADODB.Connection")
set mySourceRecordset = CreateObject("ADODB.Recordset")
mySourceConn.Open = "Provider=SQLOLEDB.1;Password=emachine;Persist
Security Info=True;User ID=sa;Initial Catalog=FileLog;Data Source=TROY"
mySQLCmdText = "INSERT INTO FileData (FileData) VALUES ('" &
DTSGlobalVariables("txtInput").Value & "')"
'Execute the mySQLCmdText, and put the data into the myRecordset object.
mySourceRecordset.Open mySQLCmdText, mySourceConn, adOpenKeyset
x.Close
set oFSO = nothing
set x = nothing
set mySourceConn = nothing
set mySourceRecordset = nothing

Case "Data2"

dim oFSO2
dim x2
dim mySourceConn2
dim mySourceRecordset2
' instantiate the Scripting Object
set oFSO2 = CreateObject("Scripting.FileSystemObject")

' Open the file
set x2 = oFSO.OpenTextFile("C:\Files\data2.txt")

' store the first line, which is the Start Date, in a global variable
DTSGlobalVariables("txtInput").Value = x.Readall
MsgBox "This files reads: " & DTSGlobalVariables("txtInput").Value

' Instantiate the ADO objects.
set mySourceConn2 = CreateObject("ADODB.Connection")
set mySourceRecordset2= CreateObject("ADODB.Recordset")
mySourceConn2.Open = "Provider=SQLOLEDB.1;Password=emachine;Persist
Security Info=True;User ID=sa;Initial Catalog=FileLog;Data Source=TROY"
mySQLCmdText = "INSERT INTO FileData (FileData) VALUES ('" &
DTSGlobalVariables("txtInput").Value & "')"
'Execute the mySQLCmdText, and put the data into the myRecordset object.
mySourceRecordset.Open mySQLCmdText, mySourceConn, adOpenKeyset
x2.Close
set oFSO2 = nothing
set x2 = nothing
set mySourceConn2 = nothing
set mySourceRecordset2 = nothing


end select




Main = DTSTaskExecResult_Success
End Function





[quoted text, click to view]

Re: Help DTS package Barry McAuslin
5/4/2004 9:52:41 PM
Try

dtsrun /S "TROY" /U "sa" /P "emachine" /N "FileTransfer" /A
"Dtinput:8=Data1"

----------

Barry McAuslin

Look inside your SQL Server files with SQL File Explorer.
Go to http://www.sqlfe.com for more information.

[quoted text, click to view]
Re: Help DTS package Sivla
5/5/2004 9:49:52 PM
I understand that i can access global variables from my script. My question
is why cant i sucessfully pass a variable in from the command prompt please
look at the command line entry
dtsrun /S "<TROY>" /U "sa" /P "emachine" /N "FileTransfer" /A
Datainput:Typeid=8 "Data1"

the /A indicates that i am passing in a paramater called Datainput with a
value of "Data1"
i have a msgbox the should say Data1 but it pops up empty. please look at
code below please help me understand why the message box wont display the
value of Datainput

Function Main()
msgbox DTSGlobalVariables("Dtinput").Value

Main = DTSTaskExecResult_Success
End Function



[quoted text, click to view]

Re: Help DTS package Dan Guzman
5/6/2004 7:36:01 AM
The variable name specified with the /A parameter needs to match your global
variable name. Try:

DTSRUN /S "<TROY>" /U "sa" /P "emachine" /N "FileTransfer" /A
Dtinput:8="Data1"

--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]

Re: Help DTS package Sivla
5/6/2004 7:45:22 PM
Thank you so much!!!!!!!!!!!!!!!!!!!!!!
[quoted text, click to view]

Re: Help DTS package Barry McAuslin
5/6/2004 8:55:52 PM
Remove the Typeid from the command.

Should be /A "Datainput:8 =Data1"

I had a mistake in my original post.

----------

Barry McAuslin

Look inside your SQL Server files with SQL File Explorer.
Go to http://www.sqlfe.com for more information.

[quoted text, click to view]

AddThis Social Bookmark Button