Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MFC, CRecordset::PrepareAndExecute() Error using MSSQL-Sever-2005

Posted on 2010-08-15
7
Medium Priority
?
672 Views
Last Modified: 2013-11-20

Hello,

I connect to an MSSQL DB 2005
Connection to DSN used in CDatabase Tested Ok.

Before I insert rec to the DB table I open the a CRecordset with

CRecordset::Open(nOpenType, ssQueryStr, dwOptions);

nOpenType = CRecordset::dynaset
ssQueryStr = select * from mytable where 1 = 0   // returns no records
dwOptions = 0
(with plan to call AddNew() and Update() later)

But this throws exception in CRecordset::PrepareAndExecute() at

// now attempt to execute the SQL Query if not executed already
if (!(m_dwOptions & executeDirect))
{
    AFX_ODBC_CALL(::SQLExecute(m_hstmt));
    if (!Check(nRetCode))
      ThrowDBException(nRetCode);
}


This had worked before.

Please any suggestion to the cause, solution or workarround to this problem?

TBlog
 
0
Comment
Question by:tblog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 

Author Comment

by:tblog
ID: 33442638

I dev with Visual C++/MFC env.

TBlog
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33443360
Are you passing values that would allow a record to be added?

eg.  Passing null to a required field would result in a failure
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33451996
Have you checked the values you pass yet ?
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

Author Comment

by:tblog
ID: 33452476

I am not passing any null.

nOpenType = CRecordset::dynaset = 0
ssQueryStr = select * from mytable where 1 = 0   // returns no records
dwOptions = 0

are passed to

CRecordset::Open(nOpenType, ssQueryStr, dwOptions);



0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 1500 total points
ID: 33452507
I don't think you understood.
For example:
Say the table has three fields (columns) that are required.  Just setting two fields to values then attempting to update will result in an error.

Check the values you are attempting to add to the table - are they valid for the field types expected ?  Are any required fields not being given values ?
0
 

Author Comment

by:tblog
ID: 33869384
Thanks guys. This was fixed by the database init configurations params. One thing I did to fix this was to specify default DB on the host. Strange.
0
 

Author Closing Comment

by:tblog
ID: 33869391
Tried solution combined with other things
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 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