装的oracle10g,创建数据库oradb,能用plsql developer连接上,用plsql developer创建了用户dbcr,密码dbcr.
 下面是连接对象的代码
//读取ini文件,保存了数据库名字oradb,用户名字dbcr和用户密码dbcr
GetPrivateProfileString("General","数据库数据源","",DBsourse.GetBuffer(200),200,strFileName);
DBsourse.ReleaseBuffer();
GetPrivateProfileString("General","数据库用户","",DBname.GetBuffer(200),200,strFileName);
DBname.ReleaseBuffer();
GetPrivateProfileString("General","数据库密码","",DBpassword.GetBuffer(200),200,strFileName);
DBpassword.ReleaseBuffer();
//连接数据库
::CoInitialize(NULL);
try
{
CString str;
str.Format("Provider=OraOLEDB.Oracle.1;Password=%s;Persist Security Info=True;User ID=%s;Data Source=%s",
DBpassword,DBname,DBsourse);
_bstr_t strConnect=str;
m_pConnection->Open(strConnect,"","",adModeUnknown);
}
catch (_com_error e)
{
MessageBox(e.Description());
return;
}
m_pConnection->Open 就是连接不上,弹出MessageBox。用ActiveX 控件Microsoft ADO DATA Control 能连接上,创建的连接字符串和m_pConnection一样,为什么m_pConnection连不上?求解!!!

解决方案 »

  1.   

    今天又试了试。
    只是把str.Format("Provider=OraOLEDB.Oracle.1;Password=%s;Persist Security Info=True;User ID=%s;Data Source=%s",DBpassword,DBname,DBsourse);
    替换成str.Format("Provider=OraOLEDB.Oracle.1;Password=dbcr;Persist Security Info=True;User ID=dbcr;Data Source=oradb");
    连接没有问题。
    之后又换回原来的str.Format("Provider=OraOLEDB.Oracle.1;Password=%s;Persist Security Info=True;User ID=%s;Data Source=%s",DBpassword,DBname,DBsourse);
    以后连接都成功。迷惑了。?