关于数据库远程访问的问题! 解决之后继续加分!

秀小川 秀小川 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区


try
{
HRESULT hr =pConn.CreateInstance("ADODB.Connection");
if (FAILED(hr))
{
AfxMessageBox("初始化失败!");
}
CString str;
str = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=Test;Data ource =192.168.1.16";
_bstr_t strConnect =str;
pConn->Open(strConnect,"","",adModeUnknown);
}
catch (_com_error e)
{

AfxMessageBox(e.Description());
}

HRESULT hr = pCommand.CreateInstance(__uuidof(Command));
hr = pRecordset.CreateInstance(__uuidof(Recordset));
pCommand->ActiveConnection = pConn;
pCommand->CommandText = "select * from TestTab ";
if (FAILED(hr))
{
pRecordset = NULL;
AfxMessageBox("can't create an instance of Recordset");
}
try
{
pRecordset=pCommand->Execute(NULL,NULL,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}


这段代码在自己机器上执行没问题,在同一局域网下别人机器上执行,红色部分会出错,提示对象名TestTab无效!
...全文
评论 29
收藏 已收藏
分享
返回顶部
秀小川
数据库 4,017 成员 39,805 内容