|
I have written a few applications in VC++ 2003 that access database information via ODBC. The typical application makes various SQL requests and displays the results in a Single Document CListView, using the report style.
The programs seem to execute fine as long as they have complete focus with uninterrupted processing time. If I try to minimize the window or check my Outlook email or use some other application while the database application processes some lengthy data retrievals, the database application hangs up.
Any ideas or suggestions to make the program work more efficiently?
Thanks for any comments!
|
|
|
|
|
|
Thanks! I had a feeling I might be headed in the direction of using threads.
|
|
|
|
|
Hi,
I need to write an application that:
1. opens a database (I connect through ODBC)
2. retrieves data from a table, using an SQL query
3. enters the retrieved data into a table in a different database
So far, I wrote the following code for steps 1 and 2:
CDatabase srcDb;
if (srcDb.Open(NULL))
{
m_sDbName = srcDb.GetConnect(); //m_sDbName is a variable of type CString
UpdateData(FALSE);
}
CRecordset rs(&srcDb);
CString strSQL;
strSQL = "SELECT * FROM table1";
rs.Open(CRecordset::snapshot, strSQL, CRecordset::readOnly);
rs.Close();
Everything works OK, (the database is connected), but when it gets to the row:
rs.Open(CRecordset::snapshot, strSQL, CRecordset::readOnly);
the application crashes, and I don't understand why...
Is this the right syntax for connecting to a database and retrieving data from a table? Can someone maybe attach some source code, so I could compare...
Another question - after the row: rs.Open(CRecordset::snapshot, strSQL, CRecordset::readOnly); is executed, how do I read the data that was retrieved by the SQL query? is it in the recordset object?
Note: I am using Visual C++ 2003.
|
|
|
|
|
Seems like you are doing something similar, but this code works for me throughout my appliations that connect to databases via ODBC. I'm also using VC++ .Net 2003.
rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL,CRecordset::none);
|
|
|
|
|
ok - but how do I see/read the data that I retrieved with the query?
And could you maybe write the rest of your sourcecode - how did you connect to the database, how do you read the data from the query?
Thanks
|
|
|
|
|
Here is a simple example. I left out A LOT of defensive coding to keep it short. Usually I am connecting to a single database within SQL server or Oracle, so I like to do this once and keep the connection open for the duration the application is active. Thus, I use a pointer to the database object and allocate memory for this with the new command (followed by a delete command later). I am usually in and out of recordsets so I tend to just create these objects within the functions that use them.
// Create and Open the Database via ODBC
CString strDSN = "DSN=The_DomainServiceName_Here; UID=User_ID_Here; PWD=Password_Here";
CDatabase* m_pDB;
m_pDB = new CDatabase;
m_pDB->OpenEx(strDSN,CDatabase::openReadOnly);
// Create and Open a Recordset connected to the database above
CString str, strMessage;
CRecordset rs(m_pDB);
str = "SELECT SOME_FIELDS FROM SOME_TABLES WHERE BLAH BLAH... ";
rs.Open(AFX_DB_USE_DEFAULT_TYPE,str,CRecordset::none);
while (!rs.IsEOF())
{
rs.GetFieldValue("FIELD_NAME1",str);
strMessage += str;
rs.GetFieldValue("FIELD_NAME2",str);
strMessage += " ";
strMessage += str;
rs.MoveNext();
}
AfxMessageBox(strMessage);
rs.Close();
m_pDB->Close();
delete m_pDB;
m_pDB = NULL;
Hope this helps.
|
|
|
|
|
Ok - thanks, it helped, but just a few questions:
1. I need to do the connection to the database from one function (when a user presses a certain button) and open the recordset in another function (when the user presses another button). How do I do this? make the CDatabase object global (a member variable)? Also, I want to get the strDSN string information from the user by opening a dialog box and letting him choose a data source. Again, how do I do this?
2. can I read the data from the records somehow else - not to a string?
3. does my class (in which I am doing all of this db handling) have to inherit from CRecordset?
3. what did you mean by: "I left out A LOT of defensive coding" ?
|
|
|
|
|
SWDevil wrote: ...the application crashes, and I don't understand why...
Have you stepped into the Open() call to find out why?
SWDevil wrote: Another question - after the row: rs.Open(CRecordset::snapshot, strSQL, CRecordset::readOnly); is executed, how do I read the data that was retrieved by the SQL query? is it in the recordset object?
Derive a class from CRecordset . Its member variables will hold the vales. Otherwise, using CRecordset directly will require you to use GetFieldValue() .
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
yeah - I tried stepping through the code..
But now I sometimes get an error saying that columns were not bound. do you know what that means?
About the recordset - what member variables hold the values? I looked at the MSDN help and could not see any variables that actually hold any data...
|
|
|
|
|
SWDevil wrote: About the recordset - what member variables hold the values? I looked at the MSDN help and could not see any variables that actually hold any data...
ClassWizard creates them.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
Hello!
Does Visual Studio 2005 Standard[^] support MFC and ATL?
If so, can the MFC libraries be statically linked to the application in the Standard edition?
Can I still develop native MFC applications, that don't use any of the .NET stuff?
Thanks in advance and best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
Yes to MFC support.
Yes to ATL support.
Yes to MFC static linkage.
Yes to MFC without .NET.
"My dog worries about the economy. Alpo is up to 99 cents a can. That's almost seven dollars in dog money" - Wacky humour found in a business magazine
|
|
|
|
|
Deal All,
In my project I am processing web pages. I want to know the different components of a web page.
I know that it is possible to extract html elements (tables, divs, images ...) using the html DOM tree. But I am not sure if its possible to recognise flash animation and pop-ups (dynamic elements) within a certain web page.
Does any one know if this is feasible or not? if it is so, can you please advise me on this task.
Thank you
llp00na
|
|
|
|
|
Can you help me abuot the text rotation like the behaviour in InDesign (text and cursor rotated).
Can yuo send me an example?
If the text is rotate also the cursor will be rotated.
Thanks.
|
|
|
|
|
Where do you want rotate text (screen, control and etc.)?
Best regards,
Eugene Pustovoyt
ICQ UIN: 161325180
|
|
|
|
|
following is the CreateFontIndirect example in msdn.
HFONT FAR PASCAL MyCreateFont( void )
{
CHOOSEFONT cf;
LOGFONT lf;
HFONT hfont;
// Initialize members of the CHOOSEFONT structure.
cf.lStructSize = sizeof(CHOOSEFONT);
cf.hwndOwner = (HWND)NULL;
cf.hDC = (HDC)NULL;
cf.lpLogFont = &lf;
cf.iPointSize = 0;
cf.Flags = CF_SCREENFONTS;
cf.rgbColors = RGB(0,0,0);
cf.lCustData = 0L;
cf.lpfnHook = (LPCFHOOKPROC)NULL;
cf.lpTemplateName = (LPSTR)NULL;
cf.hInstance = (HINSTANCE) NULL;
cf.lpszStyle = (LPSTR)NULL;
cf.nFontType = SCREEN_FONTTYPE;
cf.nSizeMin = 0;
cf.nSizeMax = 0;
cf.lfOrientation = 180; // specify angle that you want.
// Display the CHOOSEFONT common-dialog box.
ChooseFont(&cf);
// Create a logical font based on the user's
// selection and return a handle identifying
// that font.
hfont = CreateFontIndirect(cf.lpLogFont);
return (hfont);
}
Enjoy
Anderson Sheen (exteide@gmail.com)
The Extension IDE: http://www.exteide.com
|
|
|
|
|
Try this:
cf.lfEscapement = cf.lfOrientation = 180;
Best regards,
Eugene Pustovoyt
ICQ UIN: 161325180
|
|
|
|
|
|
Or to rotate basically anything at all (not just text):
CPaintDC dc(this);
int OldGMode = SetGraphicsMode(dc.m_hDC, GM_ADVANCED);
static const double pi = 4*atan(1.0);
static const double a = 30*(pi/180);
XFORM xf = {cos(a), sin(a), -sin(a), cos(a), 0, 0};
SetWorldTransform(dc.m_hDC, &xf);
int OldBkMode = dc.SetBkMode(TRANSPARENT);
dc.TextOut(0, 0, _T("This text is rotated."));
dc.SetBkMode(OldBkMode);
dc.Rectangle(100, 100, 200, 200);
SetGraphicsMode(dc.m_hDC, OldGMode);</code>
NOTE: Doesn't work in 95/98/ME
Steve
|
|
|
|
|
This is a generic query although I am right now looking for a tiny web proxy for windows and therefore seeing if I can port tinyproxy[^] to windows.
1. What are the typical challenges in porting a linux applicaiton to windows?
2. How does one go about identifying those challenges in the linux applicaiton?
thanks!
|
|
|
|
|
Can I get a property page title specified in Dialog resource editor without creating a page?
Best regards,
Eugene Pustovoyt
ICQ UIN: 161325180
|
|
|
|
|
If the page has not been created then you can not call GetWindowText() on it, but you can get the caption from the tab control (CPropertySheet::GetTabCtrl() then CTabCtrl::GetItem() with TCIF_TEXT flag).
If you want it even before the sheet is created then there might be a way using FindResource(), LoadResource(), etc.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Thank you. My choice is a FindResource(), LoadResource(), etc..
Best regards,
Eugene Pustovoyt
ICQ UIN: 161325180
|
|
|
|
|
Hello,
I'm sick of gray dialogs and windows. I'd like to skin my applications. However, I'm just a student and I can't afford buying professional skin system.
I'm looking for a free yet powerful and flexible skin system.
Can someone give me a link?
Thanks,
Allad
----
Navigator - Your best alternative to Windows Explorer
|
|
|
|