15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Recordset is read-only?!

Yong Xu -- yongxu@myself.com
Thursday, March 06, 1997

Environment: VC++ 4.2-flat, Win95, Access 97, ODBCJT32.DLL 3.40.2204

Hi there,

I am using ODBC in my application. In one of my document methods, I want
to append records into 2 recordset, let's say rs1 and rs2. I use
transaction to ensure both recordsets are updated or neither changed.
rs1 is a member variable of document object, rs2 is a local variable.
When I open rs2 as CRecordset::appendOnly(or CRecordset::none), at
output window, it shows:

'Driver not capable
State:S1C00,Native:84,Origin:[Microsoft][ODBC Microsoft Access 7.0
Driver]'

but the codes go thru and no exception is thrown. The problem is when I
want to append records to rs2, a CDBException object is thrown and the
error message reads 'Recordset is read-only'! Any guides? Below is
relevant codes snip.

// Get underlying DBMS
CString temp("");
temp.GetBuffer(50);
::SQLGetInfo(m_db.m_hdbc, SQL_DBMS_NAME, (void *)(LPCTSTR)temp, 50,
NULL);
temp.ReleaseBuffer();
if (temp.Find(_T("ACCESS")) != -1)
{// ACCESS
        // We must Close cursor library Before Begin transaction.
        ::SQLFreeStmt(m_prs1->m_hstmt, SQL_CLOSE );
        m_dbONN.BeginTrans( );
        m_prs1->Requery( );
}
else
        m_db.BeginTrans( );
        
        CRS2 rs2(&m_db);
        try{
                rs2.Open(CRecordset::snapshot,
                        NULL,	// I have overrided CRS2::GetDefaultSQL()
                        CRecordset::appendOnly); //<- Here the 'Driver
not capable'
						//message shows
        }

// codes to append a record to rs1, no problem
...

rs2.AddNew(); //<- db exception thrown here

catch(CDBException* e) // catch here
{
        m_db.Rollback(); // I can rollback without problem.
        rs2.Close();
        cursor = m_db.GetCursorRollbackBehavior();
        if(cursor == SQL_CB_CLOSE)
                m_prs1->Requery();
        else if(cursor == SQL_CB_DELETE)
        {
                m_prs1->Close();
                m_prs1->Open(CRecordset::dynaset,
                        NULL,
                        CRecordset::useBookmarks);
        }
        AfxMessageBox(e->m_strError); //<- 'Recordset is read-only'
        return 0;
}

Thank you in advance!

-- 
Truly, Yong Xu, yongxu@myself.com (or) wsy@pub.zjpta.net.cn, Hangzhou,
P.R.C




Mihir Dalal -- m_dalal@ECE.concordia.CA
Thursday, March 06, 1997



Coincidently, I too have a similar problem with my database enabled 
application (dBase III). I get this right at the startup of my application:

My debug trace at startup:

Warning: ODBC Success With Info, Driver's SQLSetConnectOption failed 
State:IM006[Microsoft][ODBC DLL] 
Driver not capable  
State:S1C00[Microsoft][ODBC Driver pack 2.0 Driver] 

Note: State IM006 is not documented in MSVC 1.52

But, surprisingly things work fine with my application after that. I have 
absolutely no problems adding/deleting/appending/updating records from my 
application. 

The trouble starts when, the database has an indexed field. Now, if I try 
to update my records, the CRecordSet::UpDate() throws a CDBException of 
type:

Warning: ODBC Success With Info, Warning: 0 rows affected by update 
operation (expected 1). 
No rows were affected by the update or delete operation. 
Warning: Throwing an Exception of type CDBException 
Warning: Throwing an Exception of type CDBException 

If someone could throw some light on this.

Mihir.  

On Thu, 6 Mar 1997, Yong Xu wrote:

> Environment: VC++ 4.2-flat, Win95, Access 97, ODBCJT32.DLL 3.40.2204
> 
> Hi there,
> 
> I am using ODBC in my application. In one of my document methods, I want
> to append records into 2 recordset, let's say rs1 and rs2. I use
> transaction to ensure both recordsets are updated or neither changed.
> rs1 is a member variable of document object, rs2 is a local variable.
> When I open rs2 as CRecordset::appendOnly(or CRecordset::none), at
> output window, it shows:
> 
> 'Driver not capable
> State:S1C00,Native:84,Origin:[Microsoft][ODBC Microsoft Access 7.0
> Driver]'
> 
> but the codes go thru and no exception is thrown. The problem is when I
> want to append records to rs2, a CDBException object is thrown and the
> error message reads 'Recordset is read-only'! Any guides? Below is
> relevant codes snip.
> 
> // Get underlying DBMS
> CString temp("");
> temp.GetBuffer(50);
> ::SQLGetInfo(m_db.m_hdbc, SQL_DBMS_NAME, (void *)(LPCTSTR)temp, 50,
> NULL);
> temp.ReleaseBuffer();
> if (temp.Find(_T("ACCESS")) != -1)
> {// ACCESS
>         // We must Close cursor library Before Begin transaction.
>         ::SQLFreeStmt(m_prs1->m_hstmt, SQL_CLOSE );
>         m_dbONN.BeginTrans( );
>         m_prs1->Requery( );
> }
> else
>         m_db.BeginTrans( );
>         
>         CRS2 rs2(&m_db);
>         try{
>                 rs2.Open(CRecordset::snapshot,
>                         NULL,	// I have overrided CRS2::GetDefaultSQL()
>                         CRecordset::appendOnly); //<- Here the 'Driver
> not capable'
> 						//message shows
>         }
> 
> // codes to append a record to rs1, no problem
> ...
> 
> rs2.AddNew(); //<- db exception thrown here
> 
> catch(CDBException* e) // catch here
> {
>         m_db.Rollback(); // I can rollback without problem.
>         rs2.Close();
>         cursor = m_db.GetCursorRollbackBehavior();
>         if(cursor == SQL_CB_CLOSE)
>                 m_prs1->Requery();
>         else if(cursor == SQL_CB_DELETE)
>         {
>                 m_prs1->Close();
>                 m_prs1->Open(CRecordset::dynaset,
>                         NULL,
>                         CRecordset::useBookmarks);
>         }
>         AfxMessageBox(e->m_strError); //<- 'Recordset is read-only'
>         return 0;
> }
> 
> Thank you in advance!
> 
> -- 
> Truly, Yong Xu, yongxu@myself.com (or) wsy@pub.zjpta.net.cn, Hangzhou,
> P.R.C
> 

 _________________________________________________________________________
     Mihir Dalal , M.Engg. (Electrical) Student
              Department of Electrical and Computer Engineering
                   Concordia University, Montreal, Canada
                http://www.ECE.Concordia.CA/~m_dalal/addr.html




Dan Kirby -- dkirby@accessone.com
Sunday, March 09, 1997

The answer to the first message your seeing is in article Q112823.

About the "0 rows affected by update operation (expected 1)" message, this
can be caused by a number of reasons but a few  common ones are:

 - You are breaking a referential integrity rule 
 - You are trying to insert/update  a null value into a non-nullable field
- You are inserting a non-unique value into a field that has a unique
index.

--dan

----------
> From: Mihir Dalal 
> To: mfc-l@netcom.com
> Subject: Re: Recordset is read-only?!
> Date: Thursday, March 06, 1997 5:49 PM
> 
> 
> 
> Coincidently, I too have a similar problem with my database enabled 
> application (dBase III). I get this right at the startup of my
application:
> 
> My debug trace at startup:
> 
> Warning: ODBC Success With Info, Driver's SQLSetConnectOption failed 
> State:IM006[Microsoft][ODBC DLL] 
> Driver not capable  
> State:S1C00[Microsoft][ODBC Driver pack 2.0 Driver] 
> 
> Note: State IM006 is not documented in MSVC 1.52
> 
> But, surprisingly things work fine with my application after that. I have

> absolutely no problems adding/deleting/appending/updating records from my

> application. 
> 
> The trouble starts when, the database has an indexed field. Now, if I try

> to update my records, the CRecordSet::UpDate() throws a CDBException of 
> type:
> 
> Warning: ODBC Success With Info, Warning: 0 rows affected by update 
> operation (expected 1). 
> No rows were affected by the update or delete operation. 
> Warning: Throwing an Exception of type CDBException 
> Warning: Throwing an Exception of type CDBException 
> 
> If someone could throw some light on this.
> 
> Mihir.  
> 
> On Thu, 6 Mar 1997, Yong Xu wrote:
> 
> > Environment: VC++ 4.2-flat, Win95, Access 97, ODBCJT32.DLL 3.40.2204
> > 
> > Hi there,
> > 
> > I am using ODBC in my application. In one of my document methods, I
want
> > to append records into 2 recordset, let's say rs1 and rs2. I use
> > transaction to ensure both recordsets are updated or neither changed.
> > rs1 is a member variable of document object, rs2 is a local variable.
> > When I open rs2 as CRecordset::appendOnly(or CRecordset::none), at
> > output window, it shows:
> > 
> > 'Driver not capable
> > State:S1C00,Native:84,Origin:[Microsoft][ODBC Microsoft Access 7.0
> > Driver]'
> > 
> > but the codes go thru and no exception is thrown. The problem is when I
> > want to append records to rs2, a CDBException object is thrown and the
> > error message reads 'Recordset is read-only'! Any guides? Below is
> > relevant codes snip.
> > 
> > // Get underlying DBMS
> > CString temp("");
> > temp.GetBuffer(50);
> > ::SQLGetInfo(m_db.m_hdbc, SQL_DBMS_NAME, (void *)(LPCTSTR)temp, 50,
> > NULL);
> > temp.ReleaseBuffer();
> > if (temp.Find(_T("ACCESS")) != -1)
> > {// ACCESS
> >         // We must Close cursor library Before Begin transaction.
> >         ::SQLFreeStmt(m_prs1->m_hstmt, SQL_CLOSE );
> >         m_dbONN.BeginTrans( );
> >         m_prs1->Requery( );
> > }
> > else
> >         m_db.BeginTrans( );
> >         
> >         CRS2 rs2(&m_db);
> >         try{
> >                 rs2.Open(CRecordset::snapshot,
> >                         NULL,	// I have overrided CRS2::GetDefaultSQL()
> >                         CRecordset::appendOnly); //<- Here the 'Driver
> > not capable'
> > 						//message shows
> >         }
> > 
> > // codes to append a record to rs1, no problem
> > ...
> > 
> > rs2.AddNew(); //<- db exception thrown here
> > 
> > catch(CDBException* e) // catch here
> > {
> >         m_db.Rollback(); // I can rollback without problem.
> >         rs2.Close();
> >         cursor = m_db.GetCursorRollbackBehavior();
> >         if(cursor == SQL_CB_CLOSE)
> >                 m_prs1->Requery();
> >         else if(cursor == SQL_CB_DELETE)
> >         {
> >                 m_prs1->Close();
> >                 m_prs1->Open(CRecordset::dynaset,
> >                         NULL,
> >                         CRecordset::useBookmarks);
> >         }
> >         AfxMessageBox(e->m_strError); //<- 'Recordset is read-only'
> >         return 0;
> > }
> > 
> > Thank you in advance!
> > 
> > -- 
> > Truly, Yong Xu, yongxu@myself.com (or) wsy@pub.zjpta.net.cn, Hangzhou,
> > P.R.C
> > 
> 
> 
_________________________________________________________________________
>      Mihir Dalal , M.Engg. (Electrical) Student
>               Department of Electrical and Computer Engineering
>                    Concordia University, Montreal, Canada
>                 http://www.ECE.Concordia.CA/~m_dalal/addr.html
> 




Become an MFC-L member | Вернуться в корень Архива |