如果是外面IP,下面的
strSQL="Provider=SQLOLEDB;Server=Gooyan;DataBase=SkillsBox;UID=sa;PWD=aaaaaaaa";
server改为IP就可以了。
局域网的可以是IP,也可以使机器名
按下面的步骤
1.stdafx.h中加入
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
2。app文件的InitInstance中加入
if(S_OK!=OleInitialize(NULL))
{
AfxMessageBox("初始化COM组件库错误");
}
下面就是数据库操作
_ConnectionPtr pConn;
_RecordsetPtr pRs;
CString strSQL;
pConn.CreateInstance(__uuidof(Connection));
pConn->CursorLocation=adUseClient;
strSQL="Provider=SQLOLEDB;Server=Gooyan;DataBase=SkillsBox;UID=sa;PWD=aaaaaaaa";
pConn->Open(_bstr_t(strSQL),"","",-1);
pRs.CreateInstance(__uuidof(Recordset));
pRs->CursorLocation=adUseClient;
pRs->PutActiveConnection(pConn.GetInterfacePtr());
pRs1.CreateInstance(__uuidof(Recordset));
pRs1->CursorLocation=adUseClient;
pRs1->PutActiveConnection(pConn.GetInterfacePtr());
strSQL="select * from catalog order by cataid";
pRs->Open(_bstr_t(strSQL),vtMissing,adOpenDynamic,adLockBatchOptimistic,adCmdText);