Bool Cadodatabase :: Open (LPCTSTR LPSTRCONNECTION, LPCTSTSTR LPSTRUSERID, LPCTSTR LPSTRPASSWORD) {HRESULT HR = S_OK;
IF (isopen ()) close ();
IF (strcmp (lpstrConnection, _t ("))! = 0) m_strconnection = lpstrConnection;
Assert (! M_strconnection.isempty ());
try {if (m_nConnectionTimeout = 0!) m_pConnection-> PutConnectionTimeout (m_nConnectionTimeout); hr = m_pConnection-> Open (_bstr_t (m_strConnection), _bstr_t (lpstrUserID), _bstr_t (lpstrPassword), NULL); return hr == S_OK;} catch (_com_error & e) {dump_com_error (e); return FALSE;}} BOOL CADODatabase :: ConnectAccess (LPCTSTR lpstrDatabaseName, LPCTSTR lpstrPassword, long lOptions) {CString strConnect; strConnect.Format ( "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =% S; ", LPSTRDATABASENAME); // Modify IF (LPSTRPASSWORD! = _T (")) {strconnect.appendformat ("Jet OLEDB: Database Password =% S;", LPSTRPASSWORD); // Modify} Return Open Open Open Open LPCTSTSTR (StrConnect);}
BOOL CADODatabase :: ConnectSQLServer (LPCTSTR lpstrDatabaseServer, LPCTSTR lpstrDatabaseName, LPCTSTR lpstrUserID, LPCTSTR lpstrPassword) {CString strConnect; strConnect.Format ( "Provider = SQLOLEDB.1; Data Source =% s; Initial Catalog =% s", lpstrDatabaseServer, lpstrDatabaseName) Return Open (LPCTSTR (StrConnect), LPSTRUSERID, LPSTRPASSWORD);
Bool Cadodatabase :: EXECUTE (LPCTSTR LPSTREXEC) {assert (m_pconnection! = Null); assert (strcmp (lpstrexec, _t ("))! = 0); _variant_t vrecords; m_nrecordsaffected = 0;
try {m_pConnection-> CursorLocation = adUseClient; m_pConnection-> Execute (_bstr_t (lpstrExec), & vRecords, adExecuteNoRecords); m_nRecordsAffected = vRecords.iVal; return TRUE;} catch (_com_error & e) {dump_com_error (e); return FALSE;}} BOOL CADODatabase :: ExecuteSqlFile (LPCTSTR lpstrFileName) {CStdioFileEx pFile; if | {return FALSE (pFile.Open (lpstrFileName, CFile :: modeRead CFile :: typeText)!);} CString strSql, strRead; strSql.Empty (); while (pfile.read.tring) {if (strread.trim (). Comparenocase (_T ("go")) == 0) {if (! strsql.isempty ()) {if (! Execute (strsql)) Return False; strsql.empty ();}} else {strsql = _ t ("") strue;}} return