I am using BulkLoad from .NET application as follows
SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class obj = new SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class();
obj.ConnectionString = "Provider=SQLOLEDB;Server=serverName;Database=dbName;Integrated Security=SSPI";
obj.ErrorLogFile = Application.StartupPath + @."\Error.log";
obj.IgnoreDuplicateKeys = true;
try
{
obj.Execute(Application.StartupPath + @."\Schema1.xsd", Application.StartupPath + @."\Data1.xml");
obj.Execute(Application.StartupPath + @."\Schema2.xsd", Application.StartupPath + @."\Data2.xml");
}
catch (Exception ex)
{
throw ex;
}
I get following error when I run my application:
InvalidCastException was unhandled by user code.
Unable to cast COM object of type 'SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class' to interface type 'SQLXMLBULKLOADLib.ISQLXMLBulkLoad4'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{88465BA7-AEEE-49A1-9499-4416287A0160}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
When I run the same code in a Console application it works alright. In my application the code is executed on a Background thread, could that be cause of exception? Please help.
Thanks
From SQL Server Books Online :
Using SQLXML Bulk Load in the .NET Environment
The reference to the Bulk Load component (xblkld4.dll) can also be added using the tlbimp.exe tool, which is available as part of .NET framework. This tool creates a managed wrapper for the native DLL (xblkld4.dll), which can then be used in any .NET project. For example:
c:\>tlbimp xblkld4.dll
This creates the managed wrapper DLL (SQLXMLBULKLOADLib.dll) that you can use in the .NET Framework project. In the .NET Framework, you add project reference to the newly created DLL.
Please follow the link for more info :
http://msdn2.microsoft.com/en-us/library/ms171878.aspx.
This will solve your issue.
Thanks
Naras.
|||I think you should use
[STAThread]
static void Main(string[] args)
{
//your code
}
|||I am having the same problem, however, running tlbimp does not fix it. I have to run tlbimp on the full path to the DLL because it can't find it unless I specify it. I get the same error. Please help!
No comments:
Post a Comment