
View Code
if (CoInitialize(NULL)!=0) { AfxMessageBox("初始化COM支持库失败!"); exit(1); } /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// try { CString strConnect; strConnect.Format("DSN=mystudentsys;"); if (m_DB.Open(NULL,false,false,"ODBC;DSN=mystudentsys;UID=Sa;PWD=HPSQL2005;",false)==0) { AfxMessageBox("Unable to Connect to the Specified Data Source"); return FALSE ; } } catch(CDBException *pE) { pE->ReportError(); pE->Delete(); return FALSE; }
本文演示了如何使用Visual C++进行COM库初始化,并通过ODBC连接到指定的数据源,包括错误处理和异常捕获机制。
1113

被折叠的 条评论
为什么被折叠?



