求数据库连接池代码 多线程的情况下,使用同一个数据库连接,程序会出错。我觉得一个数据库连接池可以解决这个问题。因为没有写过这个东西,所以望得到一段代码用于借鉴。谢谢大家。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Using ODBC Connection Pooling with CDatabase (under MFC)#if !defined( __CPDATABASE_H_ )#define __CPDATABASE_H_#pragma warning (disable : 4127) // conditional expression is constantclass CCPDatabase : public CDatabase{public: /**/ CCPDatabase() { }; // // Code Is Copied From CDatabase Source Code... // virtual BOOL OpenEx( LPCTSTR lpszConnectString, DWORD dwOptions = 0 ) { dwOptions |= noOdbcDialog; // Force NoDialog Flag For Connection Pooling ASSERT_VALID(this); ASSERT(lpszConnectString == NULL || AfxIsValidString(lpszConnectString)); ASSERT(!(dwOptions & noOdbcDialog && dwOptions & forceOdbcDialog)); // Exclusive access not supported. ASSERT(!(dwOptions & openExclusive)); m_bUpdatable = !(dwOptions & openReadOnly); TRY { m_strConnect = lpszConnectString; // Allocate the HDBC and make connection AllocConnect(dwOptions); if(!Connect(dwOptions)) return FALSE; // Verify support for required functionality and cache info VerifyConnect(); GetConnectInfo(); } CATCH_ALL(e) { Free(); THROW_LAST(); } END_CATCH_ALL return TRUE; }};#pragma warning (disable : 4127) // conditional expression is constant#endif // __CPDATABASE_H_ Connection Pool in a Static Library VC++怎样实现数据采集卡采集来的4路电压数据实时保存到txt文件中 调查:有多少人在用WTL? ctreectr每个节点设置不同的bitmap的图标 如何在对话框中创建视图 非法操作!why?????????????????????? 为什么程序(对话框)中添加最小化按钮后,按下时没反应? 怎样改变图标啊? winamp插件是怎么做的 有没有VC++技术内幕7(或者VC++.net技术内幕)这本书? 强制转换到底改变了什么? 问个低级的小问题,高手们说下啊 connect函数的问题
#define __CPDATABASE_H_#pragma warning (disable : 4127) // conditional expression is constantclass CCPDatabase : public CDatabase
{
public:
/**/ CCPDatabase()
{
};
//
// Code Is Copied From CDatabase Source Code...
//
virtual BOOL OpenEx( LPCTSTR lpszConnectString, DWORD dwOptions = 0 )
{
dwOptions |= noOdbcDialog; // Force NoDialog Flag For Connection Pooling ASSERT_VALID(this);
ASSERT(lpszConnectString == NULL || AfxIsValidString(lpszConnectString));
ASSERT(!(dwOptions & noOdbcDialog && dwOptions & forceOdbcDialog)); // Exclusive access not supported.
ASSERT(!(dwOptions & openExclusive)); m_bUpdatable = !(dwOptions & openReadOnly); TRY
{
m_strConnect = lpszConnectString; // Allocate the HDBC and make connection
AllocConnect(dwOptions);
if(!Connect(dwOptions))
return FALSE; // Verify support for required functionality and cache info
VerifyConnect();
GetConnectInfo();
}
CATCH_ALL(e)
{
Free();
THROW_LAST();
}
END_CATCH_ALL return TRUE;
}
};
#pragma warning (disable : 4127) // conditional expression is constant
#endif // __CPDATABASE_H_