PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Connection Pool problem

Reply

Connection Pool problem

 
Thread Tools Rate Thread
Old 23-12-2006, 03:59 PM   #1
sk.rasheedfarhan@gmail.com
Guest
 
Posts: n/a
Default Connection Pool problem


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.
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"));
}
}

  Reply With Quote
Old 23-12-2006, 09:15 PM   #2
Miha Markic [MVP C#]
Guest
 
Posts: n/a
Default Re: Connection Pool problem

First question of the day is, why don't you use sql server's native
provider?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

<sk.rasheedfarhan@gmail.com> wrote in message
news:1166889542.431770.222120@48g2000cwx.googlegroups.com...
> 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.
> 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"));
> }
> }
>


  Reply With Quote
Old 23-12-2006, 09:19 PM   #3
Miha Markic [MVP C#]
Guest
 
Posts: n/a
Default Re: Connection Pool problem

OTOH I see you are not using ado.net at all...

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

<sk.rasheedfarhan@gmail.com> wrote in message
news:1166889542.431770.222120@48g2000cwx.googlegroups.com...
> 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.
> 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"));
> }
> }
>


  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

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