dbTalk Databases Forums  

SQLNamespace.Initialize question - how do you uninitialize ?

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss SQLNamespace.Initialize question - how do you uninitialize ? in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mark
 
Posts: n/a

Default SQLNamespace.Initialize question - how do you uninitialize ? - 07-22-2004 , 04:36 PM






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.dts";
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;

Reply With Quote
  #2  
Old   
Darren Green
 
Posts: n/a

Default Re: SQLNamespace.Initialize question - how do you uninitialize ? - 07-23-2004 , 05:11 AM






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

Quote:
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.
Quote:
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";
Quote:
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;



Reply With Quote
  #3  
Old   
Mark
 
Posts: n/a

Default Re: SQLNamespace.Initialize question - how do you uninitialize ? - 07-23-2004 , 07:08 AM



That worked, thanks Darren...

"Darren Green" wrote:

Quote:
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;




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.