Text File Connection file name | Database Journal

Text File Connection file name

Written By
Darren Green
Darren Green
Nov 29, 1999
1 minute read


One problem with a source or destination Text File connection, is that your file name
can change. Editing the package every time you run it can be tedious and slow.
The scripts below demonstrate how to change the file name using an ActiveX script.


Example 1: Changing the file name to a date derived value

Dim oPKG
     Dim cn
     Set oPKG = DTSGlobalVariables.Parent
     Set cn = oPKG.Connections("Text File (Source)")	 
     cn.DataSource = "C:File_" & Year(Now()) & ".dat"  


Assuming the year is 1999 (which it is), the script above will change the file name for the connection called Text File (Source) to C:File_1999.dat.

 


Example 2: Changing the file name to a Global Variable value

Dim oPKG
     Dim cn
     Set oPKG = DTSGlobalVariables.Parent
     Set cn = oPKG.Connections("Text File (Source)")	 
     cn.DataSource = DTSGlobalVariables("Global_Variable_Name").Value  


This will change the file name for the connection called Text File (Source) to the value of the package Global Variable called Global_Variable_Name.

 


Example 3: Changing the file name to a value held within a SQL table

Dim cnADODB
     Dim rs
     Dim strFileName
     Dim oPKG
     Dim cn
     Set cnADODB = CreateObject("ADODB.Connection")
     cnADODB.Open "Driver={SQL Server};Server=(LOCAL);Database=master"
     Line split for display purposes
Set rs = cnADODB.Execute("SELECT value FROM master.dbo.tbVariables 
       WHERE variable = 'User_Variable_Name'") 
     strFileName = "C:" & rs("value")
     rs.Close
     cnADODB.Close
     Set cnADODB = Nothing
     Set oPKG = DTSGlobalVariables.Parent
     Set cn = oPKG.Connections("Text File (Source)")	 
     cn.DataSource = strFileName


See User Variables for a full explanation of storing values in SQL tables.

Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.