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
Solved

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

Posted on 2010-08-15
7
659 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
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 

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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.

856 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