adding OnError event to Package2Class causes error -
05-17-2004
, 03:47 AM
hey,
I have a weird problem when I try to execute a DTS-Package from C#
code.
The execution crashes, a comException is thrown "Exception from
HRESULT: 0x80040427."
I allready wrote the details in another thread on google :
http://www.developersdex.com/sql/mes...oogle%2Ecom%3E
When I execute the package via SQL-Server Enterprise Manager is works
perfect.
The unlogical thing is : when I put the line pg.OnError += ... in
comment, the package executes just fine.
Now this ain't quite convinient, is it a bug in the Package2Class, do
I make a mistake in code ?? I need the exeption-handler else I can't
check what the problem is when the package crashes exceptionally.
Has anyone an idea how to handle this ? Has anyone had the same
problem allready ??
Please, any idea is welcome, I'm struggling with this problem quite a
while !
Thanks !
Koen
my code :
public void Synchroniseer(int vertegenwoordigerID)
{
Package2Class pkg = new Package2Class();
pkg.OnError += new PackageEvents_OnErrorEventHandler(pkg_OnError);
pkg.OnQueryCancel += new
PackageEvents_OnQueryCancelEventHandler(pkg_OnQuer yCancel);
try
{
object pVarPersistStgOfHost = null;
pkg.LoadFromSQLServer("SDT_DESKTOP_003", "sa", "koen",
DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedC onnection, null,
null, null, "Coram Synchronisatie", ref pVarPersistStgOfHost);
pkg.GlobalVariables.Remove("gv_VertegenwoordigerID ");
pkg.GlobalVariables.AddGlobalVariable("gv_Vertegen woordigerID",
vertegenwoordigerID);
_DTSErrorDescription = "";
for(int i = 1; i <= pkg.Steps.Count ; i++)
{
pkg.Steps.Item(i).ExecuteInMainThread = true;
}
pkg.Execute();
if(_DTSErrorDescription != String.Empty)
{
throw new DTSErrorException(_DTSErrorDescription);
}
}
catch(System.Runtime.InteropServices.COMException ex)
{
throw new DTSErrorException(ex.Message);
}
finally
{
pkg.UnInitialize();
// force Release() on COM object
System.Runtime.InteropServices.Marshal.ReleaseComO bject(pkg);
pkg = null;
}
}
private void pkg_OnError(string EventSource, int ErrorCode, string
Source, string Description, string HelpFile, int HelpContext, string
IDofInterfaceWithError, ref bool pbCancel)
{
_DTSErrorDescription = Description;
}
private void pkg_OnQueryCancel(string EventSource, ref bool pbCancel)
{
if(pbCancel)
pbCancel = false;
} |