那位技术高手帮帮忙看看 visual 6.0下使用ADO+Oracle开发出现连接错误
阿仆来耶 2009-12-13 05:44:29 小弟,在visual C++ 下用ADO+Oracle连接数据库时,不知道怎么回事,出现发生连接错误。
void CAdo::OnInitADOConn()//CAdo下面的一个函数变量,负责连接Oracle数据库
{
::CoInitialize(NULL);
try
{
if(!AfxOleInit())
{
AfxMessageBox("OLE初始化失败!");
}
//////////////////////使用ADO连接oracle数据库/////////////////////////////
m_pConnection.CreateInstance(__uuidof(Connection)); //创建一个连接对象实例
m_pRecordset.CreateInstance(__uuidof(Command));
CString StrConnection="Provider=OraOLEDB.Oracle.1;Data Source=gym";
//进行BUG下单步测试时,处理OPEN()函数,出现问题
m_pConnection->Open((_bstr_t)StrConnection,"U079074221","K079074221",adModeUnknown);
AfxMessageBox("link success");
}
catch(_com_error e)
{
AfxMessageBox("Link error!");
AfxMessageBox(e.Description());
}
}
////是对对话框控件响应函数
void GameDialog::OnGameInitButton()
{
CAdo m_Cado;
try
{
m_Cado.OnInitADOConn();
// m_Cado.ExecuteSQL(_bstr_t("select * from MANAGER_BOOK where MNO='M0001';"));
m_Cado.m_pRecordset=m_Cado.GetRecordSet(_bstr_t("select * from MANAGER_BOOK where MNO='M0001'"));
CString m_code,m_name,m_ID;
int i=0;
while(!m_Cado.m_pRecordset->adoEOF&&i<1)
{
i++;
_variant_t theValue;
//获取sno
theValue=m_Cado.m_pRecordset->Fields->GetItem("MNO")->GetValue();
if(theValue.vt!=VT_NULL)
m_ID=(char*)_bstr_t(theValue);
theValue=m_Cado.m_pRecordset->Fields->GetItem("MNAME")->GetValue();
if(theValue.vt!=VT_NULL)
m_name=(char*)_bstr_t(theValue);
theValue=m_Cado.m_pRecordset->Fields->GetItem("MCODE")->GetValue();
if(theValue.vt!=VT_NULL)
m_code=(char*)_bstr_t(theValue);
CString strField;
strField.Format("the record is ID=%s,name=%s,code=%s",m_ID,m_name,m_code);
AfxMessageBox(strField);
}
m_Cado.m_pRecordset->Close();
}
catch(_com_error e)//异常处理
{
AfxMessageBox("读取数据库失败!");
}
}
我在单个对话框中进行测试过了,可以连接到数据库了,但是当我用同样的方法用到 菜单->对话框->控件时发生连接错误
可以编译,运行 。但是当测试时出现错误。
错误提示:ORA-12154:TNS:无法处理服务名 QQ 875161027 请教