C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Connection Leak!!!!.

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Mon Dec 25, 2006 10:10 am    Post subject: Connection Leak!!!!. Reply with quote



Hi,
I have troubles with a threaded application on W2003 server. It
seems to leave open connections behind time to time, it sums to
hundreds over a day (the application make thousands). It is using the
SQLOLEDB provider, MDAC 2.82.1830.0, SQL Server 8.00.2039 (SP4),
Windows 5.2 (3790).

I am using same connection string for all connections and Using Multi
threading. and I written code in C++.

most of them are saying i am not closing the connection properly so
here i am giving my code snippet.
Connection String:
{"Provider=SQLOLEDB;Data Source=localhost;Initial
Catalog=master;Integrated Security=SSPI;"}
For Connection Open::
try
{
//cleanup any existing open items
CloseDatabase();


//Open Connection
hres = m_pConnection.CreateInstance(
__uuidof(Connection) );
if( hres == S_OK )
{
hres = m_pConnection->Open(
m_strConnectionString.c_str());
if( hres == S_OK )
{
//Open recordset
hres m_pRecordset.CreateInstance( __uuidof(Recordset) );
if( hres == S_OK )
{
bRet = true;
}
else
{
Print
("CADOBase::CreateInstance, Creating Recordset failed
hr=%X\n"), hres
);

//m_pRecordset.Release();
}
}
else
{Print("CADOBase::CreateInstance, Open failed hr=%X\n"), hres );
}
}
else
{
Print("CADOBase::CreateInstance, Creating connection failed
hr=%X\n"),
hres );
}
}
catch(_com_error e)
{
Print("CADOBase::CreateInstance, Exception caught Error
- %X.\n"),
e.Error());
}
catch(...)
{
Print("CADOBase::CreateInstance, Unknown Exception
caught hr=%X\n"),
hres );
}
return bRet;


}


***************************************************************************­*****


For Closing:::::
try
{
if(m_pRecordset)
{
if(m_pRecordset->GetState() == adStateOpen)
{
m_pRecordset->Close();
}
m_pRecordset = NULL;
}


if(m_pConnection)
{
if(m_pConnection->GetState() == adStateOpen)
{
m_pConnection->Close();
}
m_pConnection = NULL;
}
}
catch(_com_error e)
{
Print"CADOBase::CloseDatabase, Exception caught for table Error
-
%X.\n"), e.Error());
}
catch(...)
{
Print("CADOBase::CloseDatabase,Unknown Exception caught for
table
moving on...\n"));
}
Back to top
Salt_Peter
Guest





PostPosted: Tue Dec 26, 2006 5:48 am    Post subject: Re: Connection Leak!!!!. Reply with quote



sk.rasheedfarhan (AT) gmail (DOT) com wrote:
Quote:
Hi,
I have troubles with a threaded application on W2003 server. It
seems to leave open connections behind time to time, it sums to
hundreds over a day (the application make thousands). It is using the
SQLOLEDB provider, MDAC 2.82.1830.0, SQL Server 8.00.2039 (SP4),
Windows 5.2 (3790).

I am using same connection string for all connections and Using Multi
threading. and I written code in C++.

most of them are saying i am not closing the connection properly so
here i am giving my code snippet.
Connection String:
{"Provider=SQLOLEDB;Data Source=localhost;Initial
Catalog=master;Integrated Security=SSPI;"}
For Connection Open::
try
{
//cleanup any existing open items
CloseDatabase();


//Open Connection
hres = m_pConnection.CreateInstance(
__uuidof(Connection) );
if( hres == S_OK )
{
hres = m_pConnection->Open(
m_strConnectionString.c_str());
if( hres == S_OK )
{
//Open recordset
hres > m_pRecordset.CreateInstance( __uuidof(Recordset) );
if( hres == S_OK )
{
bRet = true;
}
else
{
Print
("CADOBase::CreateInstance, Creating Recordset failed
hr=%X\n"), hres
);

//m_pRecordset.Release();
}
}
else
{Print("CADOBase::CreateInstance, Open failed hr=%X\n"), hres );
}
}
else
{
Print("CADOBase::CreateInstance, Creating connection failed
hr=%X\n"),
hres );
}
}
catch(_com_error e)
{
Print("CADOBase::CreateInstance, Exception caught Error
- %X.\n"),
e.Error());
}
catch(...)
{
Print("CADOBase::CreateInstance, Unknown Exception
caught hr=%X\n"),
hres );
}
return bRet;


}


***************************************************************************­*****


For Closing:::::
try
{
if(m_pRecordset)
{
if(m_pRecordset->GetState() == adStateOpen)
{
m_pRecordset->Close();
}
m_pRecordset = NULL;
}


if(m_pConnection)
{
if(m_pConnection->GetState() == adStateOpen)
{
m_pConnection->Close();
}
m_pConnection = NULL;
}
}
catch(_com_error e)
{
Print"CADOBase::CloseDatabase, Exception caught for table Error
-
%X.\n"), e.Error());
}
catch(...)
{
Print("CADOBase::CloseDatabase,Unknown Exception caught for
table
moving on...\n"));
}

Sorry, but your question has nothing to do with C++ whatsoever.
[OT]
Note that most libraries, including tcp/ip sockets, require a
predefined set of steps to close() a connection. Whether those
requirements are satisfied here is not something governed by this
language in any way. The same goes with threads. I'ld suggest either
consulting the relevant documentation or perhaps post to a relevant
newsgroup.
Back to top
Jack Klein
Guest





PostPosted: Tue Dec 26, 2006 10:10 am    Post subject: Re: Connection Leak!!!!. Reply with quote



On 24 Dec 2006 22:11:39 -0800, sk.rasheedfarhan (AT) gmail (DOT) com wrote in
comp.lang.c++:

Quote:
Hi,
I have troubles with a threaded application on W2003 server. It
seems to leave open connections behind time to time, it sums to
hundreds over a day (the application make thousands). It is using the
SQLOLEDB provider, MDAC 2.82.1830.0, SQL Server 8.00.2039 (SP4),
Windows 5.2 (3790).

I am using same connection string for all connections and Using Multi
threading. and I written code in C++.

most of them are saying i am not closing the connection properly so
here i am giving my code snippet.
Connection String:
{"Provider=SQLOLEDB;Data Source=localhost;Initial

[snip]

W2003 server, threads, connections, and SQL Server are all off-topic
here, since none of them are part of the C++ language.

You need to ask in either a Windows programming group like
news:comp.os.ms-windows.programmer.win32, or a database group.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.