Solved

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

Posted on 2010-08-15
7
648 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Highfive Gives IT Their Time Back

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!

Join & Write a Comment

Suggested Solutions

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: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This video discusses moving either the default database or any database to a new volume.

760 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

24 Experts available now in Live!

Get 1:1 Help Now