|
-
February 29th, 2008, 10:14 AM
#1
OLEDB Connection - need help to resolve "Timeout Expired" Error
HI all,
In the small Application what I am developing, I am estabilishing a OLE DB connection to acces the data base
It is very big query which is being fired and I always get “Timeout Expired” error at the catch statement
Following is the code what I use
Code:
try
{
HRESULT hResult;
hResult = m_pRecordset.CreateInstance(__uuidof(ADODB::Recordset));
if (FAILED(hResult))
{
throw _com_error(hResult);
}
else
{
m_pPIConnection->CursorLocation = ADODB::adUseClient;
_variant_t varQuery;
varQuery = cStrSQLQuery.AllocSysString();
hResult = m_pRecordset->Open(varQuery,m_pPIConnection.GetInterfacePtr(),ADODB::adOpenForwardOnly, ADODB::adLockReadOnly,ADODB::adCmdText);
if (FAILED(hResult))
{
throw _com_error(hResult);
}
else
{
// process the data
}
}
catch(_com_error &e)
{
nStatusFlag = N_FAILED;
BSTR bStrErrorDesc;
bStrErrorDesc = (BSTR)e.Description();
CString cStrErrorDesc(bStrErrorDesc);
gcIntfMessage.AddMessage(STR_PI_ERROR_CODE_1006 + STR_SEMICOLON + cStrErrorDesc);
}
catch(...)
{
nStatusFlag = N_FAILED;
AfxMessageBox(_T("Unhandlled exception"));
};
the database connection is established using the following lines of code
Code:
cStrConnectionString.Format(_T("Provider=PIOLEDB;Data Source=%s;Initial Catalog=PIARCHIVE;Connect Timeout=100;User Id=%s;Password=%s;"),m_sProsPIServer.cStrDSN,m_sProsPIServer.cStrUserName,m_sProsPIServer.cStrPassword);
_bstr_t bStrConnectionString = cStrConnectionString;
hr = m_pPIConnection->Open(bStrConnectionString, L"",L"", ADODB::adConnectUnspecified);
if (SUCCEEDED(hr))
{
bConnectionStatus = TRUE;
}
I tried adjusting the “Connect Timeout” property in the above connect string …. But still I Get the same
Error can some one help me to get trough?
Thanks and Regards
RK
-
March 1st, 2008, 09:06 AM
#2
Re: OLEDB Connection - need help to resolve "Timeout Expired" Error
Just for a simple information . Does a simple 'small' query works? I mean I want to know that here is a general problem or the problem is for that big query.
Best regards,
Gili
Please use code tags [code] [/code]
We would change the world, but God won't give us the sourcecode.. 
Undocumented futures are fun and useful....
_________
Gili
-
March 1st, 2008, 09:55 AM
#3
Re: OLEDB Connection - need help to resolve "Timeout Expired" Error
Also be careful with your use of a Client Cursor.
If you go directly to the DBMS box, and execute the query interactively, how long does it take?
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
March 1st, 2008, 05:05 PM
#4
Re: OLEDB Connection - need help to resolve "Timeout Expired" Error
Hi all,
as g_gili said, the simple query works,
when the query request for more data then it fails with time out expired
I was searching through internet, one place I found a guy saying me to set property called commandTimeout as zero and it worked
Code:
cStrConnectionString.Format(_T("Provider=PIOLEDB;Data Source=%s;Initial Catalog=PIARCHIVE;User Id=%s;Password=%s;"),m_sProsPIServer.cStrDSN,m_sProsPIServer.cStrUserName,m_sProsPIServer.cStrPassword);
_bstr_t bStrConnectionString = cStrConnectionString;
hr = m_pPIConnection->Open(bStrConnectionString, L"",L"", ADODB::adConnectUnspecified);
m_pPIConnection->CommandTimeout =0;
but he hasn't expalined the funda behind it?
what this proprty is for? and why it should be set to zero....
I did searched in the internet but i could not locate the correct explanation..... Can some one help me? please....
-
March 1st, 2008, 05:11 PM
#5
Re: OLEDB Connection - need help to resolve "Timeout Expired" Error
as an additional information
the declaration of m_piConnection is as follows
Code:
ADODB::_ConnectionPtr m_pPIConnection;
-
March 1st, 2008, 05:15 PM
#6
Re: OLEDB Connection - need help to resolve "Timeout Expired" Error
Does your big query work if you directly write your SQL in database ? This will tell if the problem is in your query or in your program.
-
March 1st, 2008, 05:27 PM
#7
Re: OLEDB Connection - need help to resolve "Timeout Expired" Error
HI all,
I Found the answer.....
setting the property to zerotells the connection to never time out until the query gets executed.
but the best thing to do is to optimize the query such that it does not take such a long time......
that is what i have read from one of the guys..... [ ]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|