Hi All,
I am trying to use SQLXMLBULKLOADLib.SQLXMLBulkLoad3Class to upload
XML Documents to SQL server's Database Table. The moment I made it as
a service I created and started a new Apartment thread to do the
processing.
As the method been called by an event that can fire any moment even
while processing the procedure, it locks the ErrorLogFile associated
with the SQLXMLBulkLoad3Class object. Is there any way than the Event
can wait till the processing of the thread stops and disposes?
I just want to know how to hold the event procedure that calls
function "LoadBulkToSQL"
Thank you in advance
ansu.
Code Sample:
Private Function LoadBulkToSQL(ByVal txtFileName As String, ByVal
txtSchema As String) As Boolean
Dim fCheck As System.IO.File
If fCheck.Exists(txtFileName) = False Or
fCheck.Exists(txtSchema) = False Then
'Some Error Message here
Exit Function
End If
Dim loadThread As New System.Threading.Thread(AddressOf
loadData)
loadThread.ApartmentState = Threading.ApartmentState.STA
'SQLXMLBULKLOADLib.SQLXMLBulkLoad3Class cannot work other than
single threaded environment
_SchemaPath = txtSchema
_XMLFilePath = txtFileName
loadThread.Start()
End Function
'Procedure for a new Thread
Private Sub loadData()
Dim xmlblas As New SQLXMLBULKLOADLib.SQLXMLBulkLoad3Class
xmlblas.BulkLoad = True
xmlblas.ErrorLogFile = GetConfigValue("LOGPATH") 'From
APP.Config file
xmlblas.ConnectionString = "provider=SQLOLEDB.1;Integrated
Security=SSPI;data source=MYDeskServer;initial catalog=TestDB"
xmlblas.ForceTableLock = True
Try
xmlblas.Execute(_SchemaPath.ToString,
_XMLFilePath.ToString)
Catch ex As Exception
xmlblas = Nothing
Dim evt2 As EventLog
evt2.WriteEntry("SampleService", ex.Message & " " &
ex.Source)
Exit Sub
Finally
End Try
xmlblas = Nothing
Dim evt As EventLog
evt.WriteEntry("SampleService", _XMLFilePath.ToString &
"Loaded to SQL SERVER Successfully")
End Sub