VC連接oracle數(shù)據(jù)庫及SQL Server數(shù)據(jù)庫的方法
作者:佚名
在數(shù)據(jù)庫中使用VC腳本可以方便我們的開發(fā)過程,下面就為您介紹VC連接oracle數(shù)據(jù)庫及SQL Server數(shù)據(jù)庫的方法,供您參考。
下面為您介紹VC連接oracle數(shù)據(jù)庫和SQL Server這兩種數(shù)據(jù)庫的方法,供您參考,如果您對連接oracle數(shù)據(jù)庫方面感興趣的話,不妨一看。
VC連接oracle數(shù)據(jù)庫
- _ConnectionPtr m_pConn;
- CString m_sConn="Provider=MSDAORA.1;Data Source=sode_192.168.3.9"; //使用
- ms連接庫,sode為SID,192.168.3.9為機(jī)器ip
- m_pConn.CreateInstance("ADODB.Connection");
- try
- {
- HRESULT hr=m_pConn->Open((_bstr_t)m_sConn,"sodeUser","sodePw",adConnectUnspecified);
- if (FAILED(hr))
- {
- AfxMessageBox("不能連接數(shù)據(jù)庫 source!");
- return FALSE;
- }
- }
- catch(_com_error e)
- {
- AfxMessageBox("不能打開數(shù)據(jù)庫 error!");
- return FALSE;
- }
VC連接SQL Server數(shù)據(jù)庫
- _ConnectionPtr m_pConn;
- CString m_sConn="Provider=SQLOLEDB.1;Data Source=192.168.3.9;Initial
- Catalog=sode"; //sode是數(shù)據(jù)庫服務(wù)器192.168.3.9上的一個(gè)數(shù)據(jù)庫
- m_pConn.CreateInstance("ADODB.Connection");
- try
- {
- HRESULT hr=m_pConn->Open((_bstr_t)m_sConn,"sa","mapper",adConnectUnspecified);
- if (FAILED(hr))
- {
- AfxMessageBox("不能連接數(shù)據(jù)庫 source!");
- return FALSE;
- }
- }
- catch(_com_error e)
- {
- AfxMessageBox("不能連接數(shù)據(jù)庫 error!");
- return FALSE;
- }
【編輯推薦】
責(zé)任編輯:段燃
來源:
互聯(lián)網(wǎng)