主题:MFC连接远程数据库问题
我用A PC连接B上的SQL Server2005,端口1433有监听,A,B在同一个局域网里,B的IP为192.168.0.100,(账号pd,密码pd)可是老是失败,现在我的代码是
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");
if (SUCCEEDED(hr))
{
//connect database
_bstr_t strConnect="Provider=SQLOLEDB.1;Initial Catalog=TakeawaySale;Data Source=192.168.0.100";
hr = m_pConnection->Open(strConnect,"pd","pd",adModeUnknown);
AfxMessageBox(_T("连接成功"));
}
}
catch (_com_error e)
{
CString errormessage;
// errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
}
请问应该怎么改才对?!急用!!!
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");
if (SUCCEEDED(hr))
{
//connect database
_bstr_t strConnect="Provider=SQLOLEDB.1;Initial Catalog=TakeawaySale;Data Source=192.168.0.100";
hr = m_pConnection->Open(strConnect,"pd","pd",adModeUnknown);
AfxMessageBox(_T("连接成功"));
}
}
catch (_com_error e)
{
CString errormessage;
// errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
}
请问应该怎么改才对?!急用!!!