Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Crash in MFC when inserting records

49 views
Skip to first unread message

Dirk Ringe

unread,
Sep 22, 1998, 3:00:00 AM9/22/98
to
I have a server prog connected to an MS-SQL 6.5sp4 machine. I access the
database via the ODBC MFC classes (CRecordset, CDatabase). Once in a while
(much too often for my taste) the program crashed with a structured
exception in CTime::GetYear (). I narrowed the problem down to the calls of
CRecordset::AddNew or CRecordset::Update, calling GetYear to do the RFX
stuff with an invalid (negativ?) CTime object.

Anyone noticed such problems too? Any workarounds?

Thx,
Dirk Ringe

Glenn Brude

unread,
Sep 22, 1998, 3:00:00 AM9/22/98
to Dirk Ringe
Are you sure that the DateTime field is not NULL
when calling CTime::GetYear()?
(CRecordset::IsFieldNull())

Can you replace your CTime field with a
TIMESTAMP_STRUCT?
/Glenn

Dirk Ringe

unread,
Sep 22, 1998, 3:00:00 AM9/22/98
to
The field should be null (in fact my app requires it to be null). I traced
the problem down to the case, where a negative time_t value is stored within
the CTime, then RFX_Date calls GetLocalTm (or so), which return NULL for
invalid time_t values and GetYear tries to access a structure at NULL =>
crash.

I also found an article in the knowledge base describing excactly my
situation but they state that this has been fixed with MSVC 4.2.

Thx, Dirk

Glenn Brude wrote in message <36073B01...@aptus.se>...

Michael Domnitch

unread,
Sep 28, 1998, 3:00:00 AM9/28/98
to Dirk Ringe
AFAIK you use CTime type member in your recordset. In this case you can
initialize it with 0 in your constructor (I've done it and have no problem)

class CMyRecordset : CRecordset
{
public:
CTime m_MyTime;
...
}

CMyRecordset::CMyRecordset()...
{
m_MyTime=CTime((time_t)0);
...
}

Best wishes
Michael

Michael Domnitch

unread,
Sep 28, 1998, 3:00:00 AM9/28/98
to Dirk Ringe

Dirk Ringe

unread,
Sep 29, 1998, 3:00:00 AM9/29/98
to
Yep that was it, thanks for your help. I did some research in the knowledge
base, the error was removed with vc++ 4.2 (I am using vc5sp3), i should
remove my bugs so efficient too, would spare me a lot of time.


-dirk

Michael Domnitch wrote in message <360F592B...@spb.alcatel.ru>...

0 new messages