Wrox Programmer Forums
|
SQL Server DTS Discussion specific to Data Transformation Service with SQL Server. General SQL Server discussions should use the general SQL Server forum. Readers of the book Professional SQL Server 2000 DTS with questions specific to that book should post in that book forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server DTS section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 13th, 2006, 08:36 PM
Authorized User
 
Join Date: Dec 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default DTS questions

I felt confused about the variables used in this article http://www.sqldts.com/default.aspx?243

1) ' Tell Excel where to get the data and add a named range to the workbook.
' The DTS pump is expecting a source table of "ImportTable" so we name our range that.
    Excel_WorkBook.Names.Add "ImportTable", sActualLocationOfData

What does "ImportTable" mean? Should I change it?

2)' Now set the Excel Filename on the Connection
    Set oPkg = DTSGlobalVariables.Parent
    Set oConn = oPkg.Connections("Excel File")

What does "Excel File" mean?

3) ¡®Save the changes back to the workbook. If you fail to do this then you will get ¡®a message box asking you if you want to make changes to the Excel spreadsheet¡¯
I always received this message, but can¡¯t figure out why?




Can anyone explain it to me? Thanks!!!


flyfish
__________________
flyfish
 
Old January 14th, 2006, 02:27 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
Default

"ImportTable" is a name used by the author of the article, Allan Mitchell, to create named Range in Excel, he could just as easily have used xclNR or any other name. He uses it in two places 1) in the VB Script to create the named range and then in the data pump task to extract it from Excel.

Without the named range the pump task would import the whole sheet.

"Excel File" is the name of the Connection object that connects to the Excel file

By adding the named range you are saving the excel file

David Lundell
Principal Consultant and Trainer
www.mutuallybeneficial.com
 
Old January 14th, 2006, 02:28 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
Default

By adding the named range you are modifying the excel file -- consequently it should be saved and closed, otherwise the named range won't be in the excel file when you try and access it

David Lundell
Principal Consultant and Trainer
www.mutuallybeneficial.com
 
Old January 16th, 2006, 06:58 PM
Authorized User
 
Join Date: Dec 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your response to my post!
Currently I am working on a project to load an Excel file into the database. Each file has 12 to 15 sheets which have different names and changed each month. I only need to load the data from one sheet.
In my prpject, I tried to create a DTS package to finish this auto-loading process. But I am wondering how can I pass the global variables from ActiveX script to the Excel to setup the sheet name.
In my ActiveX script code, I use two global variables: one for the Excel file location, another one for the sheet name which I can select from local table in the ActiveX script. The following was the code I used in my DTS package.

Dim sActualLocationOfData
    Dim Excel_Application
    Dim Excel_WorkBook
    Dim Excel_WorkSheet
    Dim oPkg
    Dim oConn
    Dim tsk

    dim conn
    dim myRecordset
    dim iRowCount


       set DTSGlobalVariables("MyConn").value = CreateObject("ADODB.Connection")
    set myRecordset = CreateObject("ADODB.Recordset")

       set conn = DTSGlobalVariables("MyConn").value
       conn.provider="sqloledb"
        conn.open "local", "username", "password"
     conn.DefaultDatabase = "databasename"


     SQLCmdText = "Select excel_sheetname from acct_excel"

     myRecordset.Open SQLCmdText, Conn

     msgbox(myRecordset.Fields("Excel_sheetName").value )

     DTSGlobalVariables("SheetName").value = myRecordset.Fields("Excel_sheetName")



    ' Location, which sheet and in which cells is our Data.
    ' This will produce a string like Sheet1!R14C8:R11C43

    sActualLocationOfData = "="& DTSGlobalVariables("SheetName").Value & "!"&DTSGlobalVariables("DataLocation").Value

    Msgbox(sActualLocationOfData)



    ' Create and set up the Excel File to Import
    Set Excel_Application = CreateObject("Excel.Application")

    ' Open Excel Workbook
    Set Excel_WorkBook = Excel_Application.Workbooks.Open(DTSGlobalVariable s("FileLocation").Value)

    ' Get the Worksheet
    'Set Excel_WorkSheet = Excel_WorkBook.Worksheets.Name.(DTSGlobalVariables ("SheetName").Value)

    ' Tell Excel where to get the data and add a named range to the workbook.
    ' The DTS pump is expecting a source table of "ImportTable" so we name our range that.
    Excel_WorkBook.Names.Add "ImportTable", sActualLocationOfData
(Here is my problem?)

    ' Save the changes back to the workbook. If you fail to do this then you will get
    ' a message box asking you if you want to make changes to the Excel spreadsheet
    Excel_WorkBook.Save ( I received this erroe message too)

    ' Clean Up Excel Objects
    Excel_WorkBook.Close
    Set Excel_WorkBook = Nothing
    Excel_Application.Quit
    Set Excel_Application = Nothing



    ' Now set the Excel Filename on the Connection
    Set oPkg = DTSGlobalVariables.Parent

    'set tsk = oPkg.tasks("ActiveX Script task").CustomTask
    Set oConn = oPkg.Connections(1) (my problem ?, too)

    oConn.DataSource = DTSGlobalVariables("FileLocation").Value

    ' Clean Up DTS objects
    Set oConn = Nothing
    Set oPkg = Nothing

    Main = DTSTaskExecResult_Success




flyfish
 
Old January 16th, 2006, 08:40 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
Default

Two approaches -- modify the steps your self in the ActiveX Script task or setup the Global Variables in the ActiveXScript task and then follow that with a Dynamic Properties Task.

David Lundell
Principal Consultant and Trainer
www.mutuallybeneficial.com
 
Old January 17th, 2006, 02:29 PM
Authorized User
 
Join Date: Dec 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

DTSGlobalVariables("SheetName").value = myRecordset.Fields("Excel_sheetName")
 sActualLocationOfData = "="& DTSGlobalVariables("SheetName").Value & "!"&DTSGlobalVariables("DataLocation").Value

Set Excel_Application = CreateObject("Excel.Application")

    ' Open Excel Workbook
    Set Excel_WorkBook = Excel_Application.Workbooks.Open(DTSGlobalVariable s("FileLocation").Value)

    ' Get the Worksheet
    Set Excel_WorkSheet = Excel_WorkBook.Worksheets(DTSGlobalVariables("Shee tName").Value)

    ' Tell Excel where to get the data and add a named range to the workbook.
    ' The DTS pump is expecting a source table of "ImportTable" so we name our range that.
    Excel_WorkBook.Names.Add "ImportTable", sActualLocationOfData

By using the code above, the data in the "ImportTable" still have all the sheets instead the the sheet specified by the varivable "sActualLocationOfData". Did anybody know why? Thanks in advance?

flyfish





Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET Interview Questions, C# Interview Questions, dotnetuncle .NET Framework 2.0 4 June 22nd, 2019 07:03 AM
Please help with these questions [email protected] C# 1 February 28th, 2008 07:14 PM
DTS PACKAGE QUESTIONS girl SQL Server DTS 0 June 6th, 2007 02:58 AM
dts calls a lot of dts steffi_ma SQL Server DTS 2 May 24th, 2004 07:18 PM
questions anshul Javascript How-To 1 April 12th, 2004 07:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.