数据库》MS SQL 2000。装数据库的时候选择Windowsd身份登陆的。没设置任何密码的。
ADO方式连接。连接语句:
_ConnectionPtr m_pConnection;//////////我加的BOOL CMyApp::InitInstance() //MFC程序本身固有
{
AfxEnableControlContainer();//MFC程序本身固有if(!AfxOleInit())//这就是初始化COM库
{
AfxMessageBox("com库初始化出错");
return FALSE;
}HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr))
{hr = m_pConnection->Open("driver={SQL Server};Server=XUJIAQI\GOOD;DATABASE=进销存数据库;UID=sa;PWD=","","",adModeUnknown);///连接数据库}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
} 运行期出错。输出出错语句。然后就进入软件界面了。。该怎么连啊??
ADO方式连接。连接语句:
_ConnectionPtr m_pConnection;//////////我加的BOOL CMyApp::InitInstance() //MFC程序本身固有
{
AfxEnableControlContainer();//MFC程序本身固有if(!AfxOleInit())//这就是初始化COM库
{
AfxMessageBox("com库初始化出错");
return FALSE;
}HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr))
{hr = m_pConnection->Open("driver={SQL Server};Server=XUJIAQI\GOOD;DATABASE=进销存数据库;UID=sa;PWD=","","",adModeUnknown);///连接数据库}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
} 运行期出错。输出出错语句。然后就进入软件界面了。。该怎么连啊??
{
CoInitialize(NULL);
pConn.CreateInstance(__uuidof(Connection));
pSet.CreateInstance(__uuidof(Recordset));
}
bool CAccess::Open(CString strPath)
{
try
{
CString strDBPath;
strDBPath.Format("Provider=microsoft.jet.oledb.4.0;data source=%s;user id=;password=;",
strPath.LockBuffer());
pConn->Open(strDBPath.LockBuffer(),"","",-1);
}
catch(_com_error)
{
return false;
}
return true;
}
m_pConnection->Open()
里面的内容不符合你的实际情况。