![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I written the following C# code that uses sqlnamespace and dts libraries to load and execute a dts package. The code works fine, but if I run it |
|
Does know what is going on here and how I can fix this? Thanks, Mark private void button1_Click(object sender, System.EventArgs e) { // TODO: Add in exception handling SQLNamespace oSQLNS = new SQLNamespaceClass(); SQLNamespaceObject oSQLNSObj; DTS.Package2 oPackage = new DTS.Package2Class(); int hDTSPackages; int hDTSLocalPackages; int hDTSPackage; string sConnStr = "Server=SCR4;Trusted_Connection=Yes;SrvGrp=SQL Server Group"; string filename = @"C:\Development\Solutions\BIF1\Run_DTS_Pkg_Frm_SQ LNS\Test_dotnet_dts_run.dt |
|
string user = null; string password = null; string ownerPassword = null; string operatorPassword = null; string categoryID = null; string packageID = null; string versionID = null; string name = "Test_dotnet_dts_run"; object pVarPersistStgOfHost = null; // // Connect to enterprise manager // object oConnStr = (object)sConnStr; oSQLNS.Initialize( "DTSRun", SQLNSRootType.SQLNSRootType_Server, ref oConnStr, (int)this.Handle); int hRootItem; hRootItem = oSQLNS.GetRootItem(); // // Get a handle to the appropriate package // hDTSPackages = oSQLNS.GetFirstChildItem( hRootItem, SQLNSObjectType.SQLNSOBJECTTYPE_DTSPKGS, ""); hDTSLocalPackages = oSQLNS.GetFirstChildItem( hDTSPackages, SQLNSObjectType.SQLNSOBJECTTYPE_DTS_LOCALPKGS, ""); hDTSPackage = oSQLNS.GetFirstChildItem( hDTSLocalPackages, SQLNSObjectType.SQLNSOBJECTTYPE_DTSPKG, name); // // if the package exist, delete it // if (hDTSPackage != 0) { oPackage.RemoveFromSQLServer( "SCR4", user, password, DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, packageID, versionID, name); } // // Load package from structured storage // oPackage.LoadFromStorageFile( filename, password, packageID, versionID, name, ref pVarPersistStgOfHost); // // Save package to SQL Server // oPackage.SaveToSQLServer( "SCR4", user, password, DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, ownerPassword, operatorPassword, categoryID, ref pVarPersistStgOfHost, true); // // Refresh the packages and get the new handle // oSQLNS.Refresh(hDTSLocalPackages); hDTSPackage = oSQLNS.GetFirstChildItem( hDTSLocalPackages, SQLNSObjectType.SQLNSOBJECTTYPE_DTSPKG, name); // // Create the SQLNamespace object using the package handle // oSQLNSObj = oSQLNS.GetSQLNamespaceObject(hDTSPackage); // // Run the package // oSQLNSObj.ExecuteCommandByName( "Run Package", (int)this.Handle, SQLNS.SQLNSModality.SQLNamespace_PreferModal); oSQLNS = null; oConnStr = null; oSQLNSObj = null; oPackage = null; |
#3
| |||
| |||
|
|
You need to force a object release- System.Runtime.InteropServices.Marshal.ReleaseComO bject(dmoSqlServer) -- Darren Green http://www.sqldts.com "Mark" <Mark (AT) discussions (DOT) microsoft.com> wrote in message news:10E47223-3958-4B77-8152-A75E5726FEFF (AT) microsoft (DOT) com... Hi, I written the following C# code that uses sqlnamespace and dts libraries to load and execute a dts package. The code works fine, but if I run it twice, I get the an exception indicating "The SQL Namespace has already been initialized". My code destroys the namespace object and I can't find an sqlnames.deinitialize/disconnect method. Does know what is going on here and how I can fix this? Thanks, Mark private void button1_Click(object sender, System.EventArgs e) { // TODO: Add in exception handling SQLNamespace oSQLNS = new SQLNamespaceClass(); SQLNamespaceObject oSQLNSObj; DTS.Package2 oPackage = new DTS.Package2Class(); int hDTSPackages; int hDTSLocalPackages; int hDTSPackage; string sConnStr = "Server=SCR4;Trusted_Connection=Yes;SrvGrp=SQL Server Group"; string filename = @"C:\Development\Solutions\BIF1\Run_DTS_Pkg_Frm_SQ LNS\Test_dotnet_dts_run.dt s"; string user = null; string password = null; string ownerPassword = null; string operatorPassword = null; string categoryID = null; string packageID = null; string versionID = null; string name = "Test_dotnet_dts_run"; object pVarPersistStgOfHost = null; // // Connect to enterprise manager // object oConnStr = (object)sConnStr; oSQLNS.Initialize( "DTSRun", SQLNSRootType.SQLNSRootType_Server, ref oConnStr, (int)this.Handle); int hRootItem; hRootItem = oSQLNS.GetRootItem(); // // Get a handle to the appropriate package // hDTSPackages = oSQLNS.GetFirstChildItem( hRootItem, SQLNSObjectType.SQLNSOBJECTTYPE_DTSPKGS, ""); hDTSLocalPackages = oSQLNS.GetFirstChildItem( hDTSPackages, SQLNSObjectType.SQLNSOBJECTTYPE_DTS_LOCALPKGS, ""); hDTSPackage = oSQLNS.GetFirstChildItem( hDTSLocalPackages, SQLNSObjectType.SQLNSOBJECTTYPE_DTSPKG, name); // // if the package exist, delete it // if (hDTSPackage != 0) { oPackage.RemoveFromSQLServer( "SCR4", user, password, DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, packageID, versionID, name); } // // Load package from structured storage // oPackage.LoadFromStorageFile( filename, password, packageID, versionID, name, ref pVarPersistStgOfHost); // // Save package to SQL Server // oPackage.SaveToSQLServer( "SCR4", user, password, DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, ownerPassword, operatorPassword, categoryID, ref pVarPersistStgOfHost, true); // // Refresh the packages and get the new handle // oSQLNS.Refresh(hDTSLocalPackages); hDTSPackage = oSQLNS.GetFirstChildItem( hDTSLocalPackages, SQLNSObjectType.SQLNSOBJECTTYPE_DTSPKG, name); // // Create the SQLNamespace object using the package handle // oSQLNSObj = oSQLNS.GetSQLNamespaceObject(hDTSPackage); // // Run the package // oSQLNSObj.ExecuteCommandByName( "Run Package", (int)this.Handle, SQLNS.SQLNSModality.SQLNamespace_PreferModal); oSQLNS = null; oConnStr = null; oSQLNSObj = null; oPackage = null; |
![]() |
| Thread Tools | |
| Display Modes | |
| |