Solved

CDatabase with CRecordview, CRecordset

Posted on 1998-05-22
10
502 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 101
viewing source code from eclipse 13 110
How to convert MFC::CString to UTF8 wchar_t* 10 292
Excel file not created as expected 7 79
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

820 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