Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Global Variables in DTS Package and SQL Task

Author  Topic 

safecoder@gmail.com
Starting Member

22 Posts

Posted - 2005-08-10 : 17:11:58
I'm trying to develop a DTS Package which will essentailly dump data from DB2 tables and reload them from SQL Server. The issue here is with dumping data from DB2. I have around 100 tables to dump data from and i'm using "Execute SQL Task" to do this and sample SQL Stmt would be "delete from ABC.Employee1" ...here "ABC" would be table qualifier and it varies from Development DB server to QA to Production....So, a SQL Stmt in QA sould be "delete from DEF.Employee1" where DEF would be qualifier in QA....

The catch is that the qualifier stays the same for all tables in a Development or QA or Production...So, can i save this string in Glopbal Variables and use that Variable to run the SQL Query? like

delete from @TBL_QUALIFIER.Employee1

If i cannot do that in "Execute SQL Task" step ..Is there any place that i can do this dumping?

Thanks,

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2005-08-10 : 18:27:51
How are you doing this currently? Are you performing all statements sequentially within a single execute sql task? Anyway... you can save the string to a global variable. You could then use this to dynamically set the SQLStatement property of the ExecuteSQL task(s) in an ActiveX script. I've done similar things using a placeholder string in conjunction with the vbscript Replace function.

Mark
Go to Top of Page

safecoder@gmail.com
Starting Member

22 Posts

Posted - 2005-08-11 : 09:18:51
I'm currently doing one Execute SQL Task per table...So, i have like, 100 Execute SQL Tasks which execute 100 different SQL Statements....

How can i use in ActiveX Scripts? Are there any examples? Sorry, i donot have any intro to Activex scripts in DTS....An example would be great help..Thanks
Go to Top of Page

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2005-08-11 : 22:40:11
Nigel Rivett has one floating around somewhere...

Hup! Here it is.

http://www.nigelrivett.net/DTS/SetDTSRunTimeValues.html

I have also written a teeny VB 6 program that works with DMO to do something similar. It uses the global variables but eliminates the ActiveX script. If you want any sample code, I'll post.

Sarah Berger MCSD
Go to Top of Page

safecoder@gmail.com
Starting Member

22 Posts

Posted - 2005-08-12 : 09:21:46
Sarah -

Thanks for the info...It would be great if you could post the VB snippet that you have....Thanks a ton for help...
Go to Top of Page

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2005-08-15 : 00:00:20
This is all in a form module. Command1 is a Run button, Command2 is a cancel button.

The DTS package is saved in SQL Server. You can save the DTS package to a file, and then reopen it in EM to transfer it from one SQL to another.

txtPackName is the name of the DTS package.
txtServer is the name of the SQL Server instance you want to connect to.
txtDatabase is the database you are converting into.
txtFile is what you are converting from. In my case it is a folder containing .dbf files.
txtPwd is a box for the sa password.
cmdLoc is an ellipsis opening a browse dialog for the file location.


Option Explicit
Private objPack As New DTS.Package
Private otask As DataPumpTask
Private oSQLTask As Object
Private ostep As DTS.Step
Private Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const MAX_PATH = 260
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long

Private Sub cmdLoc_Click()
Dim iNull As Integer, lpIDList As Long, lResult As Long
Dim sPath As String, udtBI As BrowseInfo

With udtBI
'Set the owner window
.hWndOwner = Me.hWnd
'lstrcat appends the two strings and returns the memory address
.lpszTitle = lstrcat("Choose Data Location", "")
'Return only if the user selected a directory
.ulFlags = BIF_RETURNONLYFSDIRS
End With

'Show the 'Browse for folder' dialog
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
'Get the path from the IDList
SHGetPathFromIDList lpIDList, sPath
'free the block of memory
CoTaskMemFree lpIDList
iNull = InStr(sPath, vbNullChar)
If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
End If

txtFile.Text = sPath
End Sub

Private Sub Command1_Click()
Dim sSQL As String
Dim Succeed As Boolean
Dim i As Integer, errCode As Long, errSource As String, errDesc As String, iErr As Integer
Dim sReplace As String

Screen.MousePointer = vbHourglass
Command1.Enabled = False
'Note that GlobalVariables collection cannot be accessed only by ordinal, not name
objPack.LoadFromSQLServer txtServer, "sa", Trim(txtPwd.Text), , , , , txtPackName.Text
With objPack
.GlobalVariables(3).Value = txtFile.Text 'FileName (Source Dir)
.GlobalVariables(2).Value = txtDatabase.Text 'DatabaseName
.GlobalVariables(1).Value = txtServer.Text 'ServerName
SetServer txtServer.Text, txtDatabase.Text, txtFile.Text
If Dir("C:\LogMMImport.txt") <> "" Then Kill "C:\LogMMImport.txt"
.LogFileName = "C:\LogMMImport.txt"
For i = 1 To .Tasks.Count
If InStr(LCase(.Tasks(i).CustomTaskID), "datapump") > 0 Then
Set otask = .Tasks(i).CustomTask
If sReplace = "" Then sReplace = Mid(otask.Description, InStr(otask.Description, "[") + 1, InStr(otask.Description, "]") - InStr(otask.Description, "[") - 1)
otask.SourceObjectName = Mid(otask.Description, InStrRev(otask.Description, "[") + 1, InStrRev(otask.Description, "]") - InStrRev(otask.Description, "[") - 1)
otask.DestinationObjectName = Replace(otask.DestinationObjectName, sReplace, txtDatabase.Text)
' ElseIf InStr(LCase(.Tasks(i).CustomTaskID), "dtsexecutesqltask") > 0 Then
' Set oSQLTask = .Tasks(i).CustomTask
' If sReplace = "" Then sReplace = Mid(oSQLTask.Description, InStr(oSQLTask.Description, "[") + 1, InStr(oSQLTask.Description, "]") - InStr(oSQLTask.Description, "[") - 1)
' oSQLTask.Name = Replace(oSQLTask.Name, sReplace, txtDatabase.Text)
' oSQLTask.Description = Replace(oSQLTask.Description, sReplace, txtDatabase.Text)
' oSQLTask.SQLStatement = Replace(oSQLTask.SQLStatement, sReplace, txtDatabase.Text)
End If
Next
.Execute
End With

Open "C:\LogMMImport.txt" For Append As #1
Print #1, "Error Messages:"
For Each ostep In objPack.Steps
If ostep.ExecutionResult = DTSStepExecResult_Failure Then
ostep.GetExecutionErrorInfo errCode, errSource, errDesc
Print #1, ostep.Description & " Failed: Code; " & errCode & " Source; " & errSource & " Desc; " & errDesc
iErr = iErr + 1
End If
Next
Close #1

If iErr <> 0 Then MsgBox "Errors Occurred: Check C:\LogMMImport.txt For Details."

objPack.UnInitialize

Set objPack = Nothing
Unload Me
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

' functions used - define before main.
Private Sub SetServer(sServer, sDatabase, sFileName)
Dim i
For i = 1 To objPack.Connections.Count
If objPack.Connections(i).ProviderID = "SQLOLEDB.1" Then
objPack.Connections(i).DataSource = sServer
objPack.Connections(i).Catalog = sDatabase
Else
objPack.Connections(i).DataSource = sFileName
End If
Next
End Sub


Sarah Berger MCSD
Go to Top of Page

safecoder@gmail.com
Starting Member

22 Posts

Posted - 2005-08-30 : 12:38:40
Sarah - Thanks for the help...
Go to Top of Page
   

- Advertisement -