社区
数据库
帖子详情
如何重复使用_ConnectionPtr 和_RecordSetPtr访问数据库?
luouII
2002-06-26 10:40:24
我的程序里需要不停的重复访问数据库,请问如何使用_ConnectionPtr 和 _RecordSetPtr来访问数据库?
...全文
199
9
打赏
收藏
如何重复使用_ConnectionPtr 和_RecordSetPtr访问数据库?
我的程序里需要不停的重复访问数据库,请问如何使用_ConnectionPtr 和 _RecordSetPtr来访问数据库?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
9 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
luouII
2002-06-26
打赏
举报
回复
to ZHENG017(风中王子)
请问 Create _RecordsetPtr的效率怎么样?会不会消耗很多的系统资源?
ZHENG017
2002-06-26
打赏
举报
回复
最好了,每次使用RecordsetPtr都重新create,而_ConnectionPtr打开后,到析构才close吧.
_ConnectionPtr是智能指针,哈哈哈,comptr,可以不考虑内存泄漏
luouII
2002-06-26
打赏
举报
回复
to storein(满天星):
谢谢,我想做一个class把_RecordsetPtr,_ConnectionPtr包在里面,初始化的时候建立连接,使用中是否可以直接调用_RecordsetPtr->Close(),然后在Destructor里面做_ConnectionPtr->Close()?主要是关心会不会有内存或者系统资源泄漏的问题。
storein
2002-06-26
打赏
举报
回复
你就在程序的APP中连接数据库,
以后你想使用连接的时候
AfxGetApp()
就可以得到你的连接(定义成PUBLIC)
退出程序才关闭
至于纪录集,在那里用就在那里定义,用了释放就完了
luouII
2002-06-26
打赏
举报
回复
to jiayp004(spark):需要做m_m_pConnectionection->Close ();么?
那么下一次是否还要做m_m_pConnectionection->open?
我访问的是SQL Server的数据库
jiayp004
2002-06-26
打赏
举报
回复
在重新使用前置空
m_pRecordset->Close (); //-3
m_m_pConnectionection->Close ();
m_pRecordset = NULL;
m_m_pConnectionection = NULL;
kingzai
2002-06-26
打赏
举报
回复
/=====================Open dbf database file
#include "stdafx.h"
#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
int main(int argc, char* argv[])
{
printf("Use ADO to open c:\\tmp\\images.dbf database file!\n");
CoInitialize(NULL);
try
{
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset");
pConn->Open("Driver={Microsoft dBASE Driver (*.dbf)};DBQ=C:\\tmp\\; DriverID=533;"
,"","",adConnectUnspecified);
pRst->Open("images", _variant_t((IDispatch *) pConn, true),
adOpenStatic, adLockReadOnly, adCmdTable);
FieldsPtr fds=pRst->GetFields();
printf("printf field name of all the table\n");
for(int i=0;i<fds->GetCount();i++)
{
FieldPtr fd=fds->GetItem(_variant_t(short(i)));
printf("%s ",(LPCTSTR)fd->GetName());
}
printf("\n");
pRst->Close();
pConn->Close();
}
catch (_com_error &e)
{
printf("Description = '%s'\n", (char*) e.Description());
}
::CoUninitialize();
return 0;
}
kingzai
2002-06-26
打赏
举报
回复
exmaple:
/=====================Open dbf database file
#include "stdafx.h"
#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
int main(int argc, char* argv[])
{
printf("Use ADO to open c:\\tmp\\images.dbf database file!\n");
CoInitialize(NULL);
try
{
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset");
pConn->Open("Driver={Microsoft dBASE Driver (*.dbf)};DBQ=C:\\tmp\\; DriverID=533;"
,"","",adConnectUnspecified);
pRst->Open("images", _variant_t((IDispatch *) pConn, true),
adOpenStatic, adLockReadOnly, adCmdTable);
FieldsPtr fds=pRst->GetFields();
printf("printf field name of all the table\n");
for(int i=0;i<fds->GetCount();i++)
{
FieldPtr fd=fds->GetItem(_variant_t(short(i)));
printf("%s ",(LPCTSTR)fd->GetName());
}
printf("\n");
pRst->Close();
pConn->Close();
}
catch (_com_error &e)
{
printf("Description = '%s'\n", (char*) e.Description());
}
::CoUninitialize();
return 0;
}
kingzai
2002-06-26
打赏
举报
回复
exmaple:
/=====================Open dbf database file
#include "stdafx.h"
#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
int main(int argc, char* argv[])
{
printf("Use ADO to open c:\\tmp\\images.dbf database file!\n");
CoInitialize(NULL);
try
{
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset");
pConn->Open("Driver={Microsoft dBASE Driver (*.dbf)};DBQ=C:\\tmp\\; DriverID=533;"
,"","",adConnectUnspecified);
pRst->Open("images", _variant_t((IDispatch *) pConn, true),
adOpenStatic, adLockReadOnly, adCmdTable);
FieldsPtr fds=pRst->GetFields();
printf("printf field name of all the table\n");
for(int i=0;i<fds->GetCount();i++)
{
FieldPtr fd=fds->GetItem(_variant_t(short(i)));
printf("%s ",(LPCTSTR)fd->GetName());
}
printf("\n");
pRst->Close();
pConn->Close();
}
catch (_com_error &e)
{
printf("Description = '%s'\n", (char*) e.Description());
}
::CoUninitialize();
return 0;
}
VC++下使用ADO操作
数据库
_
Connection
Ptr
、_
Recordset
Ptr
和_Command
Ptr
VC++下使用ADO操作
数据库
_
Connection
Ptr
、_
Recordset
Ptr
和_Command
Ptr
(转) (1)、引入ADO类 #import "c:\program files\common files\system\ado\msado15.dll" \ no_namespace \ rename ("EOF", "adoEOF") (2)、初始化COM 在MFC中可以用AfxOleInit();非MFC环境中用: CoInitialize(NULL); CoUn..
mysql(24)-ado-mfc- _
Connection
Ptr
-_
Recordset
Ptr
-增删改查
ADO库包含三个基本接口:_
Connection
Ptr
接口、_Command
Ptr
接口和_
Recordset
Ptr
接口。 基本流程: (1)初始化COM库,引入ADO库定义文件 (2)用
Connection
对象连接
数据库
(3)利用建立好的连接,通过
Connection
、Command对象执行SQL命令,或利用
Recordset
对象取得结果记录集进行查询、处理。 (4)使用完毕后关闭连接释放对象。 (1)初始化:初始化COM库,引入ADO库定义文件 ::CoInitialize(NULL); ..
VC++下使用ADO操作
数据库
的智能指针_
Connection
Ptr
、_
Recordset
Ptr
、_Command
Ptr
的方法
VC++下使用ADO操作
数据库
的智能指针_
Connection
Ptr
、_
Recordset
Ptr
、_Command
Ptr
的方法 (1)、引入ADO类 #import "c:\program files\common files\system\ado\msado15.dll" \ no_namespace \ rename ("EOF", "adoEOF") (2)、初始化COM ...
_
Connection
Ptr
、_
Recordset
Ptr
和_Command
Ptr
1. 执行简单的SQL语句插入侧重使用_
Connection
Ptr
的Execute方法。 2. 执行复杂的插入侧重使用_
Recordset
Ptr
的Open/AddNew/Update方法,注意Open得到的是游标,并非结果集(不会耗很大内存)。 3. _Command
Ptr
主要用于执行存储过程。 备注:权威的还是参照ADO.chm
_
Connection
Ptr
_Command
Ptr
_
Recordset
Prt
一旦用_
Connection
Ptr
对象连接好一个
数据库
之后, 那么_Command
Ptr
和 _
Recordset
Prt也对应的是这个
数据库
,不用再进行连接了。 _
Connection
Ptr
是专门用来进行连接的 和_
Connection
Ptr
实例化一样,只有将_
Connection
Ptr
指针创建对象后(实例化)后,才可以运用其对象对应的方法。 m_p
Recordset
.
数据库
4,017
社区成员
39,805
社区内容
发帖
与我相关
我的任务
数据库
VC/MFC 数据库
复制链接
扫一扫
分享
社区描述
VC/MFC 数据库
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章