我的VC编译出来的程序,运行的时候怎么总是显示"record set failed to open"?求救啊,谢谢各位老大.

解决方案 »

  1.   

    你提供的信息太少了。恐怕只有神才有办法帮到你。把Open记录集的部分代码贴出来吧
      

  2.   

    HRESULT Open()
    {
    CDataSource db;
    CSession session;
    HRESULT hr; CCommand<CDynamicAccessor> cmd; CDBPropSet dbinit(DBPROPSET_DBINIT);
    dbinit.AddProperty(DBPROP_AUTH_PASSWORD, "");
    dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
    dbinit.AddProperty(DBPROP_AUTH_USERID, "sa");
    dbinit.AddProperty(DBPROP_INIT_CATALOG,  "PEAK");
    dbinit.AddProperty(DBPROP_INIT_DATASOURCE, "WQ");
    dbinit.AddProperty(DBPROP_INIT_LCID, (long)2052);
    dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4); hr = db.OpenWithServiceComponents("SQLOLEDB.1", &dbinit);
    if (FAILED(hr))
    return hr; hr = session.Open(db);
    if (FAILED(hr))
    return hr; CDBPropSet propset(DBPROPSET_ROWSET);
    propset.AddProperty(DBPROP_CANFETCHBACKWARDS, true);
    propset.AddProperty(DBPROP_IRowsetScroll, true);
    propset.AddProperty(DBPROP_IRowsetChange, true);
    propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE ); hr = CCommand<CAccessor<CConsume_VSource> >::Open(session, "SELECT * FROM dbo.Consume_VSource", &propset);
    if (FAILED(hr))
    return hr; return MoveNext();
    }
      

  3.   

    有没有人帮忙我一下啊?
    hr = db.OpenWithServiceComponents("SQLOLEDB.1", &dbinit);
    hr返回是负数.
      

  4.   

    其实这个数据库是在SQL右键点击新建的,如果使用查询分析器Create database, 就没问题.
    能否问个问题,为什么右键直接新建的会这样?
      

  5.   

    干吗不用
    try
    catch.不明白,期待楼下解决。