Home > Back-end >  About MFC from SQL Server 2008 to DB2 derivative according to the problem!
About MFC from SQL Server 2008 to DB2 derivative according to the problem!

Time:10-13

Now just contact these things

Description: two servers, one is SQL, one set is DB2, a table in the SQL data into DB2 has built a table, I built two database class, one is CSQL, one is CDB2,

CDB2 class code:
Void CDB2: : OnInitDB2Conn ()
{
: : CoInitialize (NULL);

M_pConnection. CreateInstance (__uuidof (Connection));
The Provider=_bstr_t strConn="IBMDADB2. DB2COPY1; Persist Security Info=False; User ID=be made; Data Source=BSMPWS1; Location=""; Extended Properties="";
M_pConnection - & gt; Open (strConn, "made", "made", adModeUnknown);
}

_RecordsetPtr & amp; CDB2: : GetRecordSet (_bstr_t strSQL)
{
If (m_pConnection==NULL)
OnInitDB2Conn ();

M_pRecordset. CreateInstance (__uuidof (you));//initialize pointer to you
M_pRecordset - & gt; Open (strSQL, m_pConnection GetInterfacePtr (), adOpenDynamic, adLockOptimistic, adCmdText);
Return m_pRecordset;
}

BOOL CDB2: : the ExecuteSQL (_bstr_t strSQL)

{

_variant_t RecordsAffected;

If (m_pConnection==NULL)

OnInitDB2Conn ();

M_pConnection - & gt; Execute (strSQL, NULL, adCmdText);
return true;

}

The CSQL similar

Dlg class to import data section:
Void CDatabaseDlg: : OnBtnCopy ()
{
CSQL sqlCopy;
SqlCopy. OnInitSQLConn ();
CDB2 db2Copy;
Db2Copy. OnInitDB2Conn ();

_bstr_t DB2_delete="delete * from bs_info_gather";//to empty DB2 data in a database table
Db2Copy. The ExecuteSQL (DB2_delete);

_bstr_t SQL_AGENCY="select * from bs_agency";
_RecordsetPtr agency_pRecordset;
Agency_pRecordset=sqlCopy. GetRecordSet (SQL_AGENCY);//open and get the SQL bs_agency recordset

_bstr_t DB2_AGENCY="select * from bs_info_gather";
_RecordsetPtr db2_pRecordset;
Db2_pRecordset=db2Copy. GetRecordSet (DB2_AGENCY);//open and access to DB2 data set
Try
{
While (agency_pRecordset - & gt; AdoEOF==0)
{
Db2_pRecordset - & gt; AddNew (); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 1

//in the SQL AGENCY_TITLE fields in the data to the DB2 BS_TITLE
_bstr_t an1=agency_pRecordset - & gt; AGENCY_TITLE GetCollect (" ");
Db2_pRecordset - & gt; PutCollect (" BS_TITLE ", an1);

_bstr_t an2=agency_pRecordset - & gt; AGENCY_CONTENT GetCollect (" ");
Db2_pRecordset - & gt; PutCollect (" BS_CONTENT ", an2);
. .

Db2_pRecordset - & gt; MoveNext ();
}
Db2_pRecordset - & gt; The Update ();
}
.
}
When debugging in # # # # # # # # 1 throw "current recordset does not support updating, this may be the limitation of the provider, may also be selected lock type restrictions," the trouble to help me analyze analysis of what is going wrong,
  • Related