在用VC和数据库连接后运行程序时提示出错,ADO Error:[Microsoft][ODBC SQL Server Driver][SQL Server]对象名'user_info'无效。
有关的两段代码:
    _variant_t Holder, strQuery;
    strQuery = "select user_ID, user_PWD from user_info where user_ID="+m_sUSER+"";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
///////////////////////////////////////
if( FAILED(::CoInitialize(NULL)) ) 
{
    AfxMessageBox("ADO Init failed");
return false;
}
try
{
ADOConn.CreateInstance(__uuidof(Connection));
ADOConn->Open("DSN=Trade_MIS;Provider=MSDASQL","sa","", adConnectUnspecified);
}
// Catch Exceptions
catch(_com_error &e)
{
CString err;
err.Format("%s", (char*)(e.Description()) );
AfxMessageBox(err);
}
catch(...)
{
AfxMessageBox("Unknown Error...");
}

解决方案 »

  1.   

    可以参考一下:
    http://blog.csdn.net/zxhx/archive/2011/03/14/6249384.aspx
    里面有sql server的连接字符串,修改一下就行~
      

  2.   

    user_info
    ->
    [user_info]试试~
      

  3.   

    连接字符串:
    Provider=SQLOLEDB.1;Password=XXXX;Persist Security Info=True;User ID=sa;Initial Catalog=YourData;Data Source=127.0.0.1(不是本机要指定IP)另外你要查询的表名是user_info吗,有没有写错?
      

  4.   

    连接字符串:
    Driver=SQL Server;Server=.;Database=pubs;Uid=sa;Pwd=123
      

  5.   

    这里有个数据库的类,方便不易出错
    http://www.codeproject.com/KB/database/caaadoclass1.aspx#CADODatabase