dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

Help with script - sqlserver-dts

This is a discussion on Help with script - sqlserver-dts ; Hi I have the following script in a dts package which picks an xml file and reads it into the database. It does this successfully when the path and filename is specified, but I want the xml file to be ...



Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 11-25-2008, 05:38 AM
Database Newbie
 
Join Date: Jun 2008
Posts: 2
chowchow123 is on a distinguished road
Default Help with script

Hi

I have the following script in a dts package which picks an xml file and
reads it into the database. It does this successfully when the path and
filename is specified, but I want the xml file to be read dynamically and so
I've used objFSOFolder & objFSOFile.name below (highlighted the line with
'********** Problems reading file *****) The script executes but I get 'error
opening the data file' how could I rectify this



Function Main()

Set objFSO = CreateObject("Scripting.FileSystemObject")
strInboxDir = "C:\Inbox\"
strArchiveDir = "C:\Inbox\Archive\"

Set objFSOFolder = objfso.getfolder(strInboxDir)
for each objFSOFile in objfsofolder.files
if (left(objFSOFile.name, 7) ="NewFile" & right(objFSOFile.name,3) =
"xml") then
strFileNameBase = trim(right(objFSOFile.Name,len(objFSOFile.name)+7) ) &
trim(left(objFSOFile.Name, len(objFSOFile.name)-4))
master.WriteLine objFSOFile.name & " in folder @ " & now
end if

Set objBulkLoad = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload")
objBulkLoad.ConnectionString = "provider=SQLOLEDB;data
source=localhost;initial catalog=myDB; integrated security=SSPI"
objBulkLoad.ErrorLogFile = "C:\Inbox\Errorlog.txt"
objBulkLoad.Execute "C:\Schemas\Schema1.xsd", objFSOFolder &
objFSOFile.name '******** Problems reading file *******
Set objBulkLoad = Nothing
Main = DTSTaskExecResult_Success

next

Set fso = CreateObject("Scripting.FileSystemObject")

'
' Move File to the Archive Directory
'

If not fso.FileExists(strArchiveDir & "\NewFile" & strFileNameBase &
".xml") Then
fso.copyfile strInboxDir & "\NewFile" & strFileNameBase & ".xml",
strArchiveDir & "\NewFile" & strFileNameBase & ".xml",true
master.WriteLine "" & strFileNameBase & ".xml was moved to the Archive
Folder @" & now

Main = DTSTaskExecResult_Success
Else
fso.DeleteFile strInboxDir & "\NewFile" & trim(strFileNameBase) & ".xml"
master.WriteLine " NewFile" & strFileNameBase & ".xml already
exists and was Deleted @" & now
Main = DTSTaskExecResult_Success
END IF
End Function
Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 11:08 PM.