使用ADO访问数据库的时候。我用的是 try
{
m_Conn.CreateInstance(__uuidof(Connection));
_bstr_t conn="Provider=MSDAORA.1;Data Source=test;User ID=test; Password=test"; m_Conn->Open(conn,"","",0);
}
catch (_com_error e)
{
AfxMessageBox(e.ErrorMessage());
m_Conn=NULL;
m_Rec=NULL;
return;
}可是老出错。好像是这个东东写错了。Provider=MSDAORA.1;你们一般用的是什么呢?
{
m_Conn.CreateInstance(__uuidof(Connection));
_bstr_t conn="Provider=MSDAORA.1;Data Source=test;User ID=test; Password=test"; m_Conn->Open(conn,"","",0);
}
catch (_com_error e)
{
AfxMessageBox(e.ErrorMessage());
m_Conn=NULL;
m_Rec=NULL;
return;
}可是老出错。好像是这个东东写错了。Provider=MSDAORA.1;你们一般用的是什么呢?
解决方案 »
- 创建套接字失败
- 【企鹅】~【祝福帖】~生日快乐~迟到的祝福~嘿嘿~
- VS2005下怎么添加继承自CButton的CMyButton类对象啊
- 为什么会是乱码?????????????
- 请高手指点,程序编译完后运行有个问题
- 我用Visual Toolbar弄了个工具条的图片``现在要怎样才可以把它放到工具栏里?
- 全局变量使用的问题!在线等!急!
- 函数内部加了CArray<CPoint, CPoint> pointArrayStart;编译不过,为什么?
- 简单问题
- 我想在我的com中调用另外一个com
- 救我!为什么一调用ADO的Connection对象的BeginTrans方法就异常啊
- 控件中自定义消息的使用
"Provider=MSDAORA;Data Source=serverName;User ID=userName; Password=userPassword;"
BOOL CAdoConnection::ConnectOracleServer(CString dbsrc, CString user, CString pass)
{
CString strConnect = _T("Provider=OraOLEDB.Oracle.1; Data Source=") + dbsrc +
_T("; User ID=") + user +
_T("; Password=") + pass; long lOptions = adConnectUnspecified;
return Open(LPCTSTR(strConnect), lOptions);}
try
{
ADOConn.CreateInstance(__uuidof(Connection));
if(ADOConn->GetState()==adStateClosed)
ADOConn->Open("Provider=OraOLEDB.Oracle;Data Source=database;user id=scott;password=tiger","","",adConnectUnspecified);
}
// Catch Exceptions
catch(_com_error &e)
{
CString err;
err.Format("%s", (char*)(e.Description()) );
AfxMessageBox(err);
}
catch(...)
{
AfxMessageBox("Unknown Error...连接数据库失败!");
}
CString m_sConn="Provider=Microsoft.Jet.OLEDB.4.0.1;Data Source=d:\\db1.mdb";
m_pConn.CreateInstance("ADODB.Connection");
try
{
HRESULT hr=m_pConn->Open((_bstr_t)m_sConn,"","",adConnectUnspecified);
if (FAILED(hr))
{
AfxMessageBox("不能连接数据库 source!");
return FALSE;
}
}
catch(_com_error e)
{
AfxMessageBox("不能连接数据库 error!");
return FALSE;
}2.SQL Server 2000 _ConnectionPtr m_pConn;
CString m_sConn="Provider=SQLOLEDB.1;Data Source=192.168.3.9;Initial
Catalog=sode"; //sode是数据库服务器192.168.3.9上的一个数据库
m_pConn.CreateInstance("ADODB.Connection");
try
{
HRESULT hr=m_pConn->Open((_bstr_t)m_sConn,"sa","mapper",adConnectUnspecified);
if (FAILED(hr))
{
AfxMessageBox("不能连接数据库 source!");
return FALSE;
}
}
catch(_com_error e)
{
AfxMessageBox("不能连接数据库 error!");
return FALSE;
}3.Oracle 9i _ConnectionPtr m_pConn;
CString m_sConn="Provider=MSDAORA.1;Data Source=sode_192.168.3.9"; //使用
ms连接库,sode为SID,192.168.3.9为机器ip
m_pConn.CreateInstance("ADODB.Connection");
try
{
HRESULT hr=m_pConn->Open((_bstr_t)m_sConn,"sodeUser","sodePw",adConnectUnspecified);
if (FAILED(hr))
{
AfxMessageBox("不能连接数据库 source!");
return FALSE;
}
}
catch(_com_error e)
{
AfxMessageBox("不能打开数据库 error!");
return FALSE;
}
AfxEnableControlContainer();// Create ADO Connection
if( FAILED(::CoInitialize(NULL)) )
{
AfxMessageBox("ADO Init failed");
return false;
}
再试试吧