Solved

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

Posted on 2010-08-15
7
657 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 135
VBA "SendKeys" Syntax for Multiple Keystrokes 7 108
Path of Workbook 3 76
Work with App store 7 51
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

785 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