Import a CSV text file into SQL Server using DTS
Hi,
This may be a silly question but im gonna ask it anyway!
What i need to do is execute a DTS package from a CF page to read a text file and import its content to a table. I have 100's of txt files with 10,000's of rows.
The reason i think this is a silly question is because when setting the DTS package in SQL Ent, you have to specify the file name of the file you wish to import data from, therefore, its possible that you cannot change the file name. Ive done lots of research and not found one example that will allow me to do dynamically change the file name making the DTS pick up a different file. The only code ive found is as below, that executes the DTS and imports the data obtained from the file name that was set when the DTS package was created.
<cfobject
type="COM" name="objDTS" class="DTS.Package" action="CREATE">
<CFSET
r = objDTS.LoadfromSQLServer("[SERVERNAME]","[PASSWORD]","",0,"","","","[DTSPACKAGE]","")>
<cfset
p = objDTS.Execute()>
I found the following suggestion in a forum somewhere, but ive not had much luck with it
<cfset
objDTS.GlobalVariables.Item("filename").Value = "[statsFileName]">
I know an alternative to this is to read the file using CFfile or using Java and insert one by one, i dont dont like that method as it could cause performance issues with my server.
Hope someone can help me out.
regards
d
