Solved

CDatabase with CRecordview, CRecordset

Posted on 1998-05-22
10
476 Views
Last Modified: 2013-11-20
I have an Appwizard generated SDI with database support. How can I control the way CDatabase opens the database, or what is the correct syntax for the DefaultConnect? I need to use cursor libraries for the ODBC driver I am using.  I need to implement within the constraints of the Wizard created CRecordset and CRecordView.

Pat...
0
Comment
Question by:patrickm
  • 6
  • 4
10 Comments
 
LVL 3

Expert Comment

by:tma050898
ID: 1314021
THe problem is in how CRecordView is opening the recordset. Details to follow...
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1314022
The cdatabase's c'tor takes as its last argument a boolean value that indicates whether to use the cursor library.

When the recordview's OnInitalUpdate is called, the recordview's embedded recordset object is opened. When a database object is not passed to the recordset open function (as is the case here), the recordset will create the database automatically. When this happens, the recordset's m_bUseODBCCursorLib value is passed to the cdatabase c'tor.

By default, when a recordset is constructed the m_bUseODBCCursorLib is set to FALSE. That is why you are not using the cursor library with an appwiz generated application.

Therefore, in your recordview's oninitalupdate function, BEFORE the call to the CRecordView::OnInitalUpdate place the following line of code.
   
   m_pSet->m_bUseODBCCursorLib = TRUE;

Tom

0
 

Author Comment

by:patrickm
ID: 1314023
Thank you for your response.  I implemented your suggestion.  It seemed like the correct approach (as usual not documented in the MFC Encyclopedia), but I keep getting the error 'Invalid Cursor Name. Data Truncated!' when I move off the current record.  Is this unrelated to the Cursor Library?
0
 

Author Comment

by:patrickm
ID: 1314024
BTW the 'Invalid Cursor Name' error only pops up when I have changed data in the current record.
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1314025
patrickm,

Could you post only the relevant ODBC calls that are being used to position and save the data? Also, which DBMS and ODBC Driver and version are you using?

Tom
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:patrickm
ID: 1314026
I am using AppWizard gen'd Record View to navigate.  No ODBC API specific calls.  The mod's to the AppWizard skel were adding a splitter with a treeview on the left and a recordview on the right.  I added your suggested code in the OnInitalUpdate of both view classes.  I'll try genning just one view and adding the suggested code,  I must have some other problem.

The DBMS is MySQL sitting on a remote Linux server, using their ODBC driver (no cursor support vi ODBC driver or DBMS).

I'll be happy to increase the points to whatever you feel is fair.

Thanks,

Pat...
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1314027
>>I'll be happy to increase the points to whatever you feel is fair.
That is very nice of you. Actually, the original question was how to specify the use of the cursor library with the MF C database classes. This was answered and to me that question is a pretty "easy" question so its probably worth only the minimum of 50 pts.

Now, you really have a separate question which is why the cursor library isn't working for your dbms/driver.

I just tested the cursor library with my current version of the desktop drivers using Access '97 and updates work without any problem at all using an appwiz generated recordview-based application.

Lemme get out my trusty odbc reference guide and see what I can find on the cursor library.

BTW, which version of VC are you using and which version of odbc do you have installed?

Tom

0
 
LVL 3

Accepted Solution

by:
tma050898 earned 50 total points
ID: 1314028
patrickm,

I found this on dejanews.com

"Q120511:PRB: Error: "Invalid cursor name" & "No cursor name available" describes that you can sometimes get these errors, because the ODBC 1.0 spec didn't require implicit cursors to persist until the hstmt is dropped. Seemingly one needs the version 2.0 of the drivers to correct this (ODBC 2.0 is not enough). The following describes how to get it: Q125235:INF: ODBC Driver Pack 2.0 Fulfillment Kit Q&A"

Obviously, they are referring to the MS desktop drivers. I know you are not using these particular drivers, but that is not the issue. What IS IMPORTANT about this post is the following...

Since the ODBC 2.0 Programmer's Reference and SDK Guide specifically states (page 673) that supporting block scrollable cursors is required by ALL drivers that comply with the Level 1 API conformance, I incorrectly thought that every ODBC driver would therefore support cursors.

However, as the post above says, that depends on the version of ODBC that the DRIVER was written with. Therefore, if you are using ODBC 2 or 3 on your system and the driver was written with ODBC 1.0, it is entirely possible that you have the same situation described above. I really think that instead of chasing our tails, you are going to need to contact the DBMS vendor and specifically ask them...

1. What version of ODBC was used to develop the drivers (checking the data/time stamp MIGHT give you an idea of this.

2. Are scrollable cursor supported via the ODBC 2.0 spec

Tom

0
 

Author Comment

by:patrickm
ID: 1314029
Thanks very much for your input.
I am using MSVC5.0 with ODBC 3.0
The DBMS ODBC driver is based on ODBC 2.5 .
The MySQL author (Monty Widenius http://www.tcx.se ) has released the ODBC driver for his DBMS (MySQL) into the public domain.  I have the source, just haven't been intrepid enough to attack it yet.  If I use Jet/Access and attach the MySQL Database and table as a 'link' table I am able to use dynasets with the cursors available in the Jet driver.  I was just hoping to attach to the back-end without adding yet another layer.
Thanks again.
BTW MySQL is great and almost free.
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1314030
You're very welcome.

Yeah. The fact that you can use MS Access to attach to the MySQL table and then use the cursor library does prove that the problem is in the MySQL ODBC Driver. You might want to email him about this. I'm sure he's had to have heard about this from other people and might be planning another version. You never know.

Take care,
Tom

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now