本帖最后由 AOKMOKM 于 2009-08-26 15:15:10 编辑

解决方案 »

  1.   

    pConn->ConnectionString这个里面需要指定数据源
    pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=你的数据库文件路径及名称"; 
      

  2.   

    在企业管理器里能看到你附加成功的数据库吗?能正常操作吗?
    try{
    pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=zuobiao"; 
    pConn->Open("","","",adConnectUnspecified);
    }
    catch(_com_error e){
    CString strValue;
    strValue.Format(_T("%s"),(LPCTSTR)e.Description());
                    AfxMessageBox(strValue); } 用这个看看提示什么错误
      

  3.   

    Data Source=你的数据库文件路径及名称";应该是服务的ip或名字吧
    不知道password能不能省,你自己捕捉下错误看看
      

  4.   

    附加数据库之后,应该断开当前的链接会话,重新实例化一个connection,重新连接数据库,并且指定,新附加的库名.此外在附加的时候,如果不是sa,那么需要给当前的账号足够的权限。