#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "ADOEOF")
#include <stdio.h>
#include "icrsint.h"void main()
{
_ConnectionPtr pConn;
pConn.CreateInstance(_uuidof(Connection));
pConn->Provider="SQLOLEDB";
}编译通过,但是运行出错:
Debug error!
abnormal program termination!我不管访问connection什么属性或方法,Provider,open,ConnectionTimeout,ConnectionString,
都会出现这种错误,向大家求救!
解决方案 »
- MFC程序发布!!
- 怎样在Menu上添加一个TextBox?(VC6)
- 请问如何读取BMP文件的每个象素值?
- 前两天在这里看到一个关于如何在VC用宏添加注释代码的帖子 怎么不见了!!!
- 怎样调用基类CLinkButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)这个虚拟函数
- 不好意思一个sdk编译问题!
- 如何不使用ODBC连接到Oracle数据库?
- vc怎么取得avi文件中每帧的图像(bmp)阿
- 深入浅出 问题 8 菜鸟求助
- 谁能帮我把用PASCAL编写一段数据处理小程序转化VC++程序
- GetMenuItemInfo这个函数有几个参数?
- 菜鸟请教,真心请教,请教高人
no_namespace rename("EOF" , "adoEOF")//COM组件初始化
::CoInitialize(NULL);_ConnectionPtr pConnection;
_RecordsetPtr pRecordset;pConnection.CreateInstance(__uuidof(Connection));
CString strSql;
strSql.Format("select * from initparameter where trim(paratype)= 'CTI' and zhzxno = 0 and gztno = 0");
m_strConn.TrimRight(' ');
pConnection->Open(m_strConn.AllocSysString(),"","",-1);pRecordset.CreateInstance(__uuidof(Recordset));
BSTR bstrSQL = strSql.AllocSysString();
pRecordset->Open(bstrSQL,_variant_t((IDispatch*) pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);pRecordset->Close();
//关闭数据库连接指针
pConnection->Close();::CoUninitialize();
在程序的开始处加上:
1。AfxOleInit( );或者
2。CoInitialize(NULL);
{
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
} AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif // Parse the command line to see if launched as OLE server
if (RunEmbedded() || RunAutomated())
{
// Register all OLE server (factories) as running. This enables the
// OLE libraries to create objects from other applications.
COleTemplateServer::RegisterAll();
}
else
{
// When a server application is launched stand-alone, it is a good idea
// to update the system registry in case it has been damaged.
COleObjectFactory::UpdateRegistryAll();
} CMRPMWDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
} // Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
还有:m_pCon->Open("一个数据源","用户名","密码",NULL);