当前位置:首页 » 多媒体相关

本机访问数据库和异机访问数据库有什么区别?


我用ado访问sql   server2000数据库,程序在本机上无任何错误,但在局域网其它机器上运行,却出错。  
   
  以下为源代码的一部分。  
   
  主程式中有:  
   
  objdata.connectto();  
  str.format("select   *   from   manager   where   nickname   =   %s   and   password   =   %s",mstrname,mstrpwd);//mstrname,mstrpwd为输入的用户名和密码  
  objdata.opentable(str);  
   
   
  class   cadosql  
  {  
  //   属性  
  public:  
  _connectionptr   mcconnection;  
  _recordsetptr   mcrecordset;  
  cstring   mstrsource;  
  bool   mbconnected;  
  cstring   mlasterror;  
  。。。。  
   
  cadosql   objdata;  
   
  ........  
   
   
  以下为函数代码  
  bool   cadosql::connectto()  
  {  
  hresult   hr;  
  _bstr_t   source("driver={sql   server};server=chocobo;database=pizza4fun");  
  _bstr_t   user("sa");  
  _bstr_t   pwd("");  
  try  
  {  
  hr   =   mcconnection.createinstance(_uuidof(connection));  
  hr   =   mcconnection->open(source,   user,   pwd,   adconnectunspecified);  
  hr   =   mcrecordset.createinstance(_uuidof(recordset));  
  mbconnected   =   true;  
  }  
  catch(_com_error   &e)  
  {  
  cstring   strdescription,   str1,   str2;  
  if(   mlasterror   !=   e.errormessage()   )  
  {  
  mlasterror   =   e.errormessage();  
  str1   =   (lpctstr)e.description();  
  int   w   =   str1.reversefind(]);  
  //w要加1  
  str2   =   str1.mid(0,w+1);  
  str1.delete(0,w+1);  
  strdescription.format("%s\n数据库访问异常\n\n%s\n%s",   str2,   e.errormessage(),   str1);  
  //用lpctstr避免错误,cstring内部不详  
  static   cmymessagebox   box((lpctstr)strdescription);  
  }  
  trace("_com_error   exception   thrown.\n");  
  str1.format("hresult   =   %081x   \n",   e.error());  
  trace(str1);  
  displayerror(mcconnection);  
  mbconnected   =   false;  
  }  
  if(   mbconnected   )   mstrsource   =   (const   char*)source;  
  return   mbconnected;  
  }  
   
   
  //打开表并返回指定的记录集,需用户自己调用->close方法将其关闭  
   
  bool   cadosql::opentable(cstring   strcommand)  
  {  
  if(   !mbconnected   ) return   false;  
   
  hresult   hr;  
  _bstr_t   query   =   (_bstr_t)strcommand;  
  _bstr_t   source   =   (_bstr_t)mstrsource;  
  try  
  {  
  hr   =   mcrecordset->open(query,   source,   adopendynamic,   adlockoptimistic,   adcmdtext);  
  return   true;  
  }  
  catch(_com_error   &e)  
  {  
  *****************************************************程序执行中断在此  
  cstring   strdescription,   str1,   str2;  
  if(   mlasterror   !=   e.errormessage()   )  
  {  
  mlasterror   =   e.errormessage();  
  str1   =   (lpctstr)e.description();  
  int   w   =   str1.reversefind(]);  
  //w要加1  
  str2   =   str1.mid(0,w+1);  
  str1.delete(0,w+1);  
  strdescription.format("%s\n数据库访问异常\n\n%s\n%s",   str2,   e.errormessage(),   str1);  
  //用lpctstr避免错误,cstring内部不详  
  static   cmymessagebox   box((lpctstr)strdescription);  
  }  
  trace("_com_error   exception   thrown.\n");  
  str1.format("hresult   =   %081x   \n",   e.error());  
  trace(str1);  
  displayerror(mcconnection);  
  return   false;  
  }  
  }  
   
  如果不设断点,程式报错:  
   
  数据库访问异常,idispatch   error   #3149  
  用户"(null)"登录失败。原因:未与信任sql   server连接相关联。

.

推荐阅读

  • 烽火网络校园网解决方案 信息化解决方案/案例资料中心 [详细内容]
  • Network Appliance公布2005财年收益情况 [详细内容]
  • 我今天发现的小5的最新死机BUG [详细内容]
  • 天寓网络精品课程平台整体解决方案 信息化解决方案/案例资料中心 [详细内容]
  • Taxsoftware.com助IRS加速纳税申请 [详细内容]
  • 我发现的在宝典里从未见他人提起的6个BUG [详细内容]
  • 华硕服务器品质完美缔造企业知识平台 信息化解决方案/案例资料中心 [详细内容]
  • 网友回答:

    讨论区

    Login