#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,
都会出现这种错误,向大家求救!

解决方案 »

  1.   

    #import "c:\program files\common files\system\ado\msado15.dll"\
    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();
      

  2.   

    可能是没初始化COM。
    在程序的开始处加上:
    1。AfxOleInit( );或者
    2。CoInitialize(NULL);
      

  3.   

    同意楼上的一定要 初始化,要明白ado也是com接口,使用前一定要初始化
      

  4.   

    同样的问题我也遇上了,应该不是初始化的问题吧!因为我有如下代码,但是仍然是那个错误。BOOL CMRPMWApp::InitInstance()
    {
    // 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;
    }
      

  5.   

    昨天晚上我才遇到这个问题,就是没有初始化引起的,加个::CoInitialize(NULL)就OK了。
    还有:m_pCon->Open("一个数据源","用户名","密码",NULL);
      

  6.   

    只需要添加CoInitialize(NULL);初始化