本帖最后由 ppwxjd 于 2010-04-22 18:18:42 编辑

解决方案 »

  1.   

    捕获异常,看下错误。
    try
    {
        //你的代码......
    }
    catch(_com_error &e)
    {
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());    // Print Com errors.
        TRACE(_T("Error\n"));
        TRACE(_T("\tCode = %08lx\n"), e.Error());
        TRACE(_T("\tErrorMessage = %s\n"), (LPCTSTR)e.ErrorMessage());
        TRACE(_T("\tSource = %s\n"), (LPCTSTR) bstrSource);
        TRACE(_T("\tDescription = %s\n"), (LPCTSTR) bstrDescription);
      

  2.   

    m_ConnectStr="Driver={SQL Server};Server=WANGPAN\\SQLEXPRESS;Persist Security Info=True;Database=tb_video;UID=sa;PWD=123;";
    m_pConnect->ConnectionString=m_ConnectStr.AllocSysString();
    m_pConnect->Open("","","",-1);
    我已经连接了。
    错误为
    + bstrSource {"Microsoft OLE DB Provider for ODBC Drivers" (1)} _bstr_t+ + bstrDescription {"[Microsoft][ODBC SQL Server Driver][SQL Server]关键字 'select' 附近有语法错误。" (1)} _bstr_t我已经把改正为select * from tb_UserInfo了,但是怎么还是有语法错误呢?
      

  3.   

    Error
    Code = 80040e14
    ErrorMessage = IDispatch error #3092
    Source = Microsoft OLE DB Provider for SQL Server
    _CrtDbgReport: String too long or IO Error
    这是调试打印醋的错误
      

  4.   

    m_pConnect->Open("","","",-1);这里也要 user pwd的
      

  5.   

    connection string 永远不能为空,必须指定,否则ado怎么知道你要操作什么东西?
      

  6.   

    m_pConnect->ConnectionString=m_ConnectStr.AllocSysString();
    这里已经导入了,m_ConnectStr=="Driver={SQL Server};Server=WANGPAN\\SQLEXPRESS;Persist Security Info=True;Database=tb_video;UID=sa;PWD=123";所以可以为空
      

  7.   

    前面已经导入了,如果是这个open错误的话会弹出提示对话框的。肯定不是这个错误
      

  8.   

    sqlStr="selcet * from tb_UserInfo";
    无语了!!!!
      

  9.   

    sqlStr="selcet * from tb_UserInfo;";