ADO异常:未知错误

lflljt 2010-07-03 10:19:46
try
{
// 创建Connection对象
m_Connection.CreateInstance("ADODB.Connection");

// 设置连接字符串,必须是BSTR型或者_bstr_t类型
_bstr_t strConnect =strConn;
//m_Command.CreateInstance(__uuidof(Command));
m_Connection->Open(strConnect,"","",adModeUnknown);
//等待时间10s
m_Connection->ConnectionTimeout=10;

}
catch 未知错误
why???
...全文
76 点赞 收藏 9
写回复
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lflljt 2010-07-05
Thanks!!!
回复
_菜菜 2010-07-03
这种情况一般都是连接字串不对的原因比较大
你用.udl文件来配置连接字串,然后再把连接字串复制到你的代码里面,再试试看
回复
BlueMap 2010-07-03
_bstr_t strConnect =strConn;????strConn?????
回复
lflljt 2010-07-03
找不到错。。。。
回复
精锐掷矛手 2010-07-03

连接SQLServer

BOOL CDataADO::InitADO()

{ try {
char appPath[256];

GetCurrentDirectory(256,appPath); //取得应用程序当前路径

CString filePath; //保存Ini文件名

filePath.Format("%s",appPath);

filePath += "\\";

filePath += "SYS.INI";

CString strAdoConn;

char temp1[100];

GetPrivateProfileString("DatabaseConfig","Server","",temp1,100,filePath);

strserver = (TCHAR *)temp1;

GetPrivateProfileString("DatabaseConfig","Database","",temp1,100,filePath);

strdbName = temp1;

GetPrivateProfileString("DatabaseConfig","User","",temp1,100,filePath);

strUser = temp1;

GetPrivateProfileString("DatabaseConfig","PWD","",temp1,100,filePath);

strPassword = temp1;

strAdoConn.Format("Provider=SQLOLEDB.1;Password=%s;Persist Security Info=False;User ID=%s;Initial

Catalog=%s;Data Source=%s",strPassword,strUser,strdbName,strserver);

m_pCon.CreateInstance(_uuidof(Connection));

m_pCon->ConnectionString = (_bstr_t)strAdoConn;

m_pCon->Open("","","",NULL);

//m_pCom.CreateInstance("ADODB.Command");

m_pRs.CreateInstance(_uuidof(Recordset));

Is_InitADO=TRUE;

return TRUE;

}
catch(_com_error)

{
MessageBox(0,"请检查系统配置信息", "数据库连接失败",MB_OK|MB_ICONINFORMATION);

return FALSE;

} catch(...) {
MessageBox(0,"系统错误", "数据库连接失败",MB_OK|MB_ICONINFORMATION);

return FALSE ;

} }
回复
lflljt 2010-07-03
strConn是CString类型,
strConn=“Provider=SQLOLEDB.1;Server=localhost;Database=Test_stu; uid=sa; pwd=123456”;
回复
chexlong 2010-07-03
strConn是什么,类型和值各是什么
回复
lflljt 2010-07-03
catch报的错内容是:未指定的错误
回复
没看明白
回复
发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告
暂无公告