InvalidCastException: QueryInterface for interface
SQLXMLBULKLOADLib.ISQLXMLBulkLoad failed.
The code works with windows application.
Hoping that someone can help me with this problem. It has halted the project
for over a w

My kode:
My webservice:
Public Function LagreStilingsannonse(ByVal XML As System.Xml.XmlElement,
ByVal AutorisasjonsStreng As String) As Long
Dim serviceModule1 As ServerContax.ServiceModule = New
ServerContax.ServiceModule
Return serviceModule1.LagreA(XML) 'Lagrer xml shemaet
End Function 'LagreStilingsannonse
Heres the code for the service module (its not a module, but a class, just a
name):
Friend Function LagreA(ByVal XMLelement As System.Xml.XmlElement) As Long
Private dbstreng2 As String
=" Provider=sqloledb;server=TEAMSERVER;data
base=XML;UserID=testBruker;Passwor
d=test" ‘<- works
Private savepath As String = "C:"
<-code clipped->
Dim objBL As SQLXMLBULKLOADLib.SQLXMLBulkLoad3Class = New
SQLXMLBULKLOADLib.SQLXMLBulkLoad3Class
objBL.ConnectionString = dbstreng2 '<- Here it fail with: InvalidCastExcepti
on
objBL.ErrorLogFile = savepath + "\" + "error.log"
objBL.CheckConstraints = False
objBL.TempFilePath = savepath
objBL.BulkLoad = True
objBL.SGDropTables = False
objBL.SchemaGen = True
objBL.Execute(savepath & "\" & XSD, datastream)
return 0
end function
Appreciate any help!
--
Marius Pettersen
.Net developer
MP ProductionsFrom what I have read, you can't execute a bulk load in a multi-threaded env
ironment. You need to instantiate a single thread and then perform the bulk
load. Once I set that up, I got past the problem you are having, but I am
unable to connect to my database. If you get past that problem, please let
me know.
Private Sub BulkLoadXML()
Dim bulkload As New Thread(New ThreadStart(AddressOf ExecuteBulkCall
))
bulkload.ApartmentState = ApartmentState.STA
bulkload.Start()
bulkload.Join()
End Sub
Private Sub ExecuteBulkCall()
Dim _bulkInstance As New SQLXMLBulkLoad3Class
_bulkInstance.ConnectionString = _strConn
_bulkInstance.ErrorLogFile = "c:\temp\xmlerror.log"
_bulkInstance.KeepIdentity = False
_bulkInstance.Execute("c:\SampleSchema.xsd", "c:\SampleXMLData.xml")
End Sub|||Yes, I figure i could solve it like this, but the method has the xml as
argument. I cant put an argument in a AdressOf method.
Anyway, can I do this? How can we send information to a thred?
franksag: What you can do is copy the code/method to a windows or console
application. Then you can se if it's working.
My code works fine in a windows application.
"franksag" wrote:
> From what I have read, you can't execute a bulk load in a multi-threaded
> environment. You need to instantiate a single thread and then perform
> the bulk load. Once I set that up, I got past the problem you are
> having, but I am unable to connect to my database. If you get past
> that problem, please let me know.
> Private Sub BulkLoadXML()
> Dim bulkload As New Thread(New ThreadStart(AddressOf
> ExecuteBulkCall))
> bulkload.ApartmentState = ApartmentState.STA
> bulkload.Start()
> bulkload.Join()
> End Sub
> Private Sub ExecuteBulkCall()
> Dim _bulkInstance As New SQLXMLBulkLoad3Class
> _bulkInstance.ConnectionString = _strConn
> _bulkInstance.ErrorLogFile = "c:\temp\xmlerror.log"
> _bulkInstance.KeepIdentity = False
> _bulkInstance.Execute("c:\SampleSchema.xsd",
> "c:\SampleXMLData.xml")
> End Sub
>
> --
> franksag
> ---
> Posted via http://www.codecomments.com
> ---
>
No comments:
Post a Comment