Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

999 lines
25 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: wkspace.cpp
  6. //
  7. // Contents: DB workspace
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #include "pch.cpp"
  13. #include "TLSdef.h"
  14. #include "server.h"
  15. #include "wkspace.h"
  16. #include "utils.h"
  17. #include "globals.h"
  18. /////////////////////////////////////////////////////////////
  19. //
  20. // Try to save some memory
  21. //
  22. //
  23. JBInstance __TlsDbWorkSpace::g_JbInstance;
  24. static TLSDbWorkSpacePool g_WorkSpacePool;
  25. typedef map<PVOID, PVOID> ACQUIREDHANDLELIST;
  26. CCriticalSection AcquiredHandleListLock;
  27. ACQUIREDHANDLELIST AcquiredHandleList;
  28. LONG g_lWorkSpacePoolDeleted = 0;
  29. #if DBG
  30. DWORD g_dwNumWorkSpaceAllocated = 0;
  31. #endif
  32. //-----------------------------------------------
  33. //
  34. // Table for work item storage,
  35. //
  36. //
  37. JBSession g_WkItemSession(__TlsDbWorkSpace::g_JbInstance);
  38. JBDatabase g_WkItemDatabase(g_WkItemSession);
  39. WorkItemTable g_WkItemTable(g_WkItemDatabase);
  40. //--------------------------------------------------------
  41. BOOL
  42. TLSGetESEError(
  43. const JET_ERR jetErrCode,
  44. LPTSTR* pszString
  45. )
  46. /*++
  47. --*/
  48. {
  49. JBError jbError;
  50. return jbError.GetJBErrString(
  51. jetErrCode,
  52. pszString
  53. );
  54. }
  55. //--------------------------------------------------------
  56. WorkItemTable*
  57. GetWorkItemStorageTable()
  58. {
  59. BOOL bSuccess = TRUE;
  60. //
  61. // verify session and database is correct.
  62. //
  63. if(g_WkItemSession.IsValid() == FALSE)
  64. {
  65. SetLastError(ERROR_INVALID_PARAMETER);
  66. return NULL;
  67. }
  68. if(g_WkItemDatabase.IsValid() == FALSE)
  69. {
  70. SetLastError(ERROR_INVALID_PARAMETER);
  71. return NULL;
  72. }
  73. if(g_WkItemTable.IsValid() == FALSE)
  74. {
  75. bSuccess = g_WkItemTable.OpenTable(
  76. TRUE,
  77. JET_bitTableUpdatable
  78. );
  79. if(bSuccess == FALSE)
  80. {
  81. LPTSTR pString = NULL;
  82. SetLastError(SET_JB_ERROR(g_WkItemTable.GetLastJetError()));
  83. TLSGetESEError(g_WkItemTable.GetLastJetError(), &pString);
  84. TLSLogEvent(
  85. EVENTLOG_ERROR_TYPE,
  86. TLS_E_SERVICEINIT,
  87. TLS_E_JB_OPENTABLE,
  88. g_WkItemTable.GetTableName(),
  89. g_WkItemTable.GetLastJetError(),
  90. (pString != NULL) ? pString : _TEXT("")
  91. );
  92. if(pString != NULL)
  93. {
  94. LocalFree(pString);
  95. }
  96. }
  97. }
  98. return (bSuccess == TRUE) ? &g_WkItemTable : NULL;
  99. }
  100. //--------------------------------------------------------
  101. DWORD
  102. CloseWorkSpacePool()
  103. {
  104. DWORD dwNumWkSpace = g_WorkSpacePool.GetNumberAvailable();
  105. TLSDbWorkSpace* jbWkSpace=NULL;
  106. DWORD dwErrCode=ERROR_SUCCESS;
  107. //
  108. // Mark workspace pool deleted, this is for backup/restore
  109. // that it will close entire workspace pool but RPC context
  110. // rundown might happen after we close the workspace pool
  111. //
  112. InterlockedExchange(
  113. &g_lWorkSpacePoolDeleted,
  114. 1
  115. );
  116. #if DBG
  117. DBGPrintf(
  118. DBG_INFORMATION,
  119. DBG_FACILITY_HANDLEPOOL,
  120. DBGLEVEL_FUNCTION_TRACE,
  121. _TEXT("CloseWorkSpace() - Total %d, Num Available %d\n"),
  122. g_dwNumWorkSpaceAllocated,
  123. dwNumWkSpace
  124. );
  125. #endif
  126. while(dwNumWkSpace)
  127. {
  128. jbWkSpace = NULL;
  129. dwErrCode=g_WorkSpacePool.AcquireHandle(
  130. &jbWkSpace,
  131. INFINITE
  132. );
  133. if(jbWkSpace)
  134. delete jbWkSpace;
  135. dwNumWkSpace--;
  136. #if DBG
  137. g_dwNumWorkSpaceAllocated--;
  138. #endif
  139. }
  140. AcquiredHandleListLock.Lock();
  141. if(AcquiredHandleList.empty() != TRUE)
  142. {
  143. ACQUIREDHANDLELIST::iterator it;
  144. for(it = AcquiredHandleList.begin(); it != AcquiredHandleList.end(); it++)
  145. {
  146. if((*it).second != NULL)
  147. {
  148. jbWkSpace = (TLSDbWorkSpace*) (*it).second;
  149. delete jbWkSpace;
  150. #if DBG
  151. g_dwNumWorkSpaceAllocated--;
  152. DBGPrintf(
  153. DBG_INFORMATION,
  154. DBG_FACILITY_HANDLEPOOL,
  155. DBGLEVEL_FUNCTION_TRACE,
  156. _TEXT("Close Allocated WorkSpace()...\n")
  157. );
  158. #endif
  159. }
  160. else
  161. {
  162. TLSASSERT(FALSE);
  163. }
  164. }
  165. AcquiredHandleList.erase(AcquiredHandleList.begin(), AcquiredHandleList.end());
  166. }
  167. AcquiredHandleListLock.UnLock();
  168. g_WkItemTable.CloseTable();
  169. g_WkItemDatabase.CloseDatabase();
  170. g_WkItemSession.EndSession();
  171. #if DBG
  172. if( 0 != g_dwNumWorkSpaceAllocated )
  173. {
  174. TLSASSERT(FALSE);
  175. }
  176. #endif
  177. //
  178. // Delete log file so that to prevent long database recovery
  179. //
  180. __TlsDbWorkSpace::g_JbInstance.JBTerminate(
  181. JET_bitTermComplete,
  182. TRUE
  183. );
  184. return ERROR_SUCCESS;
  185. }
  186. //--------------------------------------------------------
  187. BOOL
  188. IsValidAllocatedWorkspace(
  189. PTLSDbWorkSpace p
  190. )
  191. /*++
  192. Abstract:
  193. Verify an allocated workspace handle is in our
  194. allocated list.
  195. --*/
  196. {
  197. BOOL bSuccess = TRUE;
  198. ACQUIREDHANDLELIST::iterator it;
  199. AcquiredHandleListLock.Lock();
  200. it = AcquiredHandleList.find(p);
  201. bSuccess = (it != AcquiredHandleList.end());
  202. AcquiredHandleListLock.UnLock();
  203. return bSuccess;
  204. }
  205. //--------------------------------------------------------
  206. void
  207. ReleaseWorkSpace(
  208. PTLSDbWorkSpace *p
  209. )
  210. /*
  211. */
  212. {
  213. if( g_lWorkSpacePoolDeleted == 1 )
  214. {
  215. //
  216. // DB workspace pool has been deleted, acquired workspace
  217. // handle will be deleted via AcquireHandleList
  218. //
  219. // overactive assert here... there is a race condition possible,
  220. // this assert is to verify that this if statement handles it.
  221. TLSASSERT(FALSE);
  222. return;
  223. }
  224. TLSASSERT(p != NULL && *p != NULL);
  225. if(p != NULL)
  226. {
  227. ACQUIREDHANDLELIST::iterator it;
  228. AcquiredHandleListLock.Lock();
  229. it = AcquiredHandleList.find(*p);
  230. if(it != AcquiredHandleList.end())
  231. {
  232. AcquiredHandleList.erase(it);
  233. }
  234. else
  235. {
  236. TLSASSERT(FALSE);
  237. }
  238. AcquiredHandleListLock.UnLock();
  239. }
  240. DBGPrintf(
  241. DBG_INFORMATION,
  242. DBG_FACILITY_HANDLEPOOL,
  243. DBGLEVEL_FUNCTION_TRACE,
  244. _TEXT("Releasing workspace 0x%08x...\n"),
  245. *p
  246. );
  247. if(*p)
  248. {
  249. (*p)->Cleanup();
  250. g_WorkSpacePool.ReleaseHandle(*p);
  251. *p = NULL;
  252. }
  253. }
  254. //--------------------------------------------------------
  255. TLSDbWorkSpace*
  256. AllocateWorkSpace(
  257. DWORD dwWaitTime /* INFINITE */
  258. )
  259. /*
  260. */
  261. {
  262. TLSDbWorkSpace* jbWkSpace=NULL;
  263. BOOL bSuccess;
  264. DBGPrintf(
  265. DBG_INFORMATION,
  266. DBG_FACILITY_HANDLEPOOL,
  267. DBGLEVEL_FUNCTION_TRACE,
  268. _TEXT("Allocating a workspace...\n")
  269. );
  270. bSuccess = g_WorkSpacePool.AcquireHandleEx(
  271. GetServiceShutdownHandle(),
  272. &jbWkSpace,
  273. dwWaitTime
  274. );
  275. if(bSuccess == TRUE)
  276. {
  277. DBGPrintf(
  278. DBG_INFORMATION,
  279. DBG_FACILITY_HANDLEPOOL,
  280. DBGLEVEL_FUNCTION_TRACE,
  281. _TEXT("Allocated 0x%08x...\n"),
  282. jbWkSpace
  283. );
  284. AcquiredHandleListLock.Lock();
  285. AcquiredHandleList[jbWkSpace] = jbWkSpace;
  286. AcquiredHandleListLock.UnLock();
  287. }
  288. else
  289. {
  290. DBGPrintf(
  291. DBG_INFORMATION,
  292. DBG_FACILITY_HANDLEPOOL,
  293. DBGLEVEL_FUNCTION_TRACE,
  294. _TEXT("Can't allocate workspace - %d are in use...\n"),
  295. AcquiredHandleList.size()
  296. );
  297. }
  298. return jbWkSpace;
  299. }
  300. //--------------------------------------------------------
  301. DWORD
  302. GetNumberOfWorkSpaceHandle()
  303. {
  304. return g_WorkSpacePool.GetNumberAvailable();
  305. }
  306. //--------------------------------------------------------
  307. BOOL
  308. TLSJbInitDatabaseEngine(
  309. IN JBSession& jbSession,
  310. IN JBDatabase& jbDatabase,
  311. IN LPCTSTR szDatabaseFile,
  312. IN LPCTSTR szUserName,
  313. IN LPCTSTR szPassword
  314. )
  315. /*++
  316. --*/
  317. {
  318. BOOL bSuccess = TRUE;
  319. DWORD dwErrCode;
  320. if(jbSession.IsValid() == FALSE)
  321. {
  322. bSuccess = jbSession.BeginSession(
  323. szUserName,
  324. szPassword
  325. );
  326. if(bSuccess == FALSE)
  327. {
  328. LPTSTR pString = NULL;
  329. TLSGetESEError(jbSession.GetLastJetError(), &pString);
  330. TLSLogEvent(
  331. EVENTLOG_ERROR_TYPE,
  332. TLS_E_DBGENERAL,
  333. TLS_E_JB_BEGINSESSION,
  334. jbSession.GetLastJetError(),
  335. (pString != NULL) ? pString : _TEXT("")
  336. );
  337. if(pString != NULL)
  338. {
  339. LocalFree(pString);
  340. }
  341. DBGPrintf(
  342. DBG_ERROR,
  343. DBG_FACILITY_JETBLUE,
  344. DBGLEVEL_FUNCTION_ERROR,
  345. _TEXT("Error : Initialize JetBlue session - error code %d\n"),
  346. jbSession.GetLastJetError()
  347. );
  348. dwErrCode = SET_JB_ERROR(jbSession.GetLastJetError());
  349. SetLastError(dwErrCode);
  350. TLSASSERT(FALSE);
  351. goto cleanup;
  352. }
  353. }
  354. //
  355. // Open Database
  356. if(jbDatabase.IsValid() == FALSE)
  357. {
  358. bSuccess = jbDatabase.OpenDatabase(szDatabaseFile);
  359. if(bSuccess == FALSE)
  360. {
  361. JET_ERR errCode = jbDatabase.GetLastJetError();
  362. if(errCode != JET_errFileNotFound)
  363. {
  364. if(errCode == JET_errDatabaseCorrupted)
  365. {
  366. TLSLogErrorEvent(TLS_E_CORRUPT_DATABASE);
  367. }
  368. else
  369. {
  370. LPTSTR pString = NULL;
  371. TLSGetESEError(errCode, &pString);
  372. //
  373. // other type of error
  374. //
  375. TLSLogEvent(
  376. EVENTLOG_ERROR_TYPE,
  377. TLS_E_DBGENERAL,
  378. TLS_E_JB_OPENDATABASE,
  379. szDatabaseFile,
  380. errCode,
  381. (pString != NULL) ? pString : _TEXT("")
  382. );
  383. if(pString != NULL)
  384. {
  385. LocalFree(pString);
  386. }
  387. }
  388. DBGPrintf(
  389. DBG_ERROR,
  390. DBG_FACILITY_JETBLUE,
  391. DBGLEVEL_FUNCTION_ERROR,
  392. _TEXT("Error : Can't create database because OpenDatabase failed with %d\n"),
  393. errCode
  394. );
  395. dwErrCode = SET_JB_ERROR(errCode);
  396. SetLastError(dwErrCode);
  397. TLSASSERT(FALSE);
  398. return FALSE;
  399. }
  400. // create a new database file
  401. bSuccess = jbDatabase.CreateDatabase(szDatabaseFile);
  402. if(bSuccess == FALSE)
  403. {
  404. LPTSTR pString = NULL;
  405. TLSGetESEError(jbDatabase.GetLastJetError(), &pString);
  406. TLSLogEvent(
  407. EVENTLOG_ERROR_TYPE,
  408. TLS_E_DBGENERAL,
  409. TLS_E_JB_CREATEDATABASE,
  410. szDatabaseFile,
  411. jbDatabase.GetLastJetError(),
  412. (pString != NULL) ? pString : _TEXT("")
  413. );
  414. if(pString != NULL)
  415. {
  416. LocalFree(pString);
  417. }
  418. DBGPrintf(
  419. DBG_ERROR,
  420. DBG_FACILITY_JETBLUE,
  421. DBGLEVEL_FUNCTION_ERROR,
  422. _TEXT("Error : can't create new database - error code %d\n"),
  423. jbDatabase.GetLastJetError()
  424. );
  425. dwErrCode = SET_JB_ERROR(jbDatabase.GetLastJetError());
  426. SetLastError(dwErrCode);
  427. }
  428. }
  429. }
  430. cleanup:
  431. return bSuccess;
  432. }
  433. //--------------------------------------------------------
  434. BOOL
  435. InitializeWorkSpacePool(
  436. IN int num_workspace,
  437. IN LPCTSTR szDatabaseFile,
  438. IN LPCTSTR szUserName,
  439. IN LPCTSTR szPassword,
  440. IN LPCTSTR szChkPointDirPath,
  441. IN LPCTSTR szTempDirPath,
  442. IN LPCTSTR szLogDirPath,
  443. IN BOOL bUpdatable
  444. )
  445. /*
  446. */
  447. {
  448. DWORD dwErrCode=ERROR_SUCCESS;
  449. int index=0;
  450. BOOL bSuccess=TRUE;
  451. BOOL bWkItemSuccess = TRUE;
  452. DBGPrintf(
  453. DBG_ERROR,
  454. DBG_FACILITY_JETBLUE,
  455. DBGLEVEL_FUNCTION_ERROR,
  456. _TEXT("InitializeWorkSpacePool()... %d\n"),
  457. num_workspace
  458. );
  459. if(__TlsDbWorkSpace::g_JbInstance.IsValid() == FALSE)
  460. {
  461. bSuccess = TLSJbInstanceInit(
  462. __TlsDbWorkSpace::g_JbInstance,
  463. szChkPointDirPath,
  464. szTempDirPath,
  465. szLogDirPath
  466. );
  467. if(bSuccess != TRUE)
  468. {
  469. TLSASSERT(FALSE);
  470. goto cleanup;
  471. }
  472. }
  473. if(g_WkItemTable.IsValid() == FALSE)
  474. {
  475. //
  476. // Initialize session for WorkItemTable, critical
  477. // error if this failed
  478. //
  479. bWkItemSuccess = TLSJbInitDatabaseEngine(
  480. g_WkItemSession,
  481. g_WkItemDatabase,
  482. szDatabaseFile,
  483. szUserName,
  484. szPassword
  485. );
  486. if(bWkItemSuccess == FALSE)
  487. {
  488. TLSASSERT(FALSE);
  489. goto cleanup;
  490. }
  491. }
  492. //
  493. // Allocate number of workspace
  494. //
  495. for(index=0; index < num_workspace; index++)
  496. {
  497. PTLSDbWorkSpace pJbWkSpace=NULL;
  498. pJbWkSpace = new TLSDbWorkSpace();
  499. if(pJbWkSpace == NULL)
  500. {
  501. break;
  502. }
  503. if(pJbWkSpace->InitWorkSpace(
  504. TRUE,
  505. szDatabaseFile,
  506. szUserName,
  507. szPassword,
  508. NULL,
  509. NULL,
  510. bUpdatable) == FALSE)
  511. {
  512. delete pJbWkSpace;
  513. break;
  514. }
  515. g_WorkSpacePool.ReleaseHandle(pJbWkSpace);
  516. #if DBG
  517. g_dwNumWorkSpaceAllocated++;
  518. #endif
  519. }
  520. //
  521. // WorkSpace pool has been initialized
  522. //
  523. InterlockedExchange(
  524. &g_lWorkSpacePoolDeleted,
  525. 0
  526. );
  527. cleanup:
  528. if(bWkItemSuccess == FALSE)
  529. {
  530. // critical error, can't initialize session for workitem table.
  531. SetLastError(TLS_E_INIT_WORKSPACE);
  532. return FALSE;
  533. }
  534. //
  535. // We need at least 3 workspace, one for update/insert
  536. // and two for enumeration
  537. //
  538. if(index < num_workspace)
  539. {
  540. SetLastError(TLS_E_INIT_WORKSPACE);
  541. }
  542. return index >= num_workspace;
  543. }
  544. //--------------------------------------------------------
  545. //
  546. // Initialize DB workspace...
  547. //
  548. //--------------------------------------------------------
  549. BOOL
  550. TLSJbInstanceInit(
  551. IN OUT JBInstance& jbInstance,
  552. IN LPCTSTR szChkPointDirPath,
  553. IN LPCTSTR szTempDirPath,
  554. IN LPCTSTR szLogDirPath
  555. )
  556. /*
  557. */
  558. {
  559. //
  560. // Setup system parameters
  561. //
  562. BOOL bSuccess=TRUE;
  563. DWORD dwErrCode;
  564. if(jbInstance.IsValid() == TRUE)
  565. {
  566. jbInstance.SetLastJetError(JET_errAlreadyInitialized);
  567. goto cleanup;
  568. }
  569. //
  570. // Set JetBlue parameter and initialize it
  571. //
  572. if(szChkPointDirPath != NULL)
  573. {
  574. bSuccess = jbInstance.SetSystemParameter(
  575. 0,
  576. JET_paramSystemPath,
  577. 0,
  578. (unsigned char *)szChkPointDirPath
  579. );
  580. if(bSuccess == FALSE)
  581. {
  582. dwErrCode = SET_JB_ERROR(jbInstance.GetLastJetError());
  583. SetLastError(dwErrCode);
  584. goto cleanup;
  585. }
  586. }
  587. if(szTempDirPath != NULL)
  588. {
  589. bSuccess = jbInstance.SetSystemParameter(
  590. 0,
  591. JET_paramTempPath,
  592. 0,
  593. (unsigned char *)szTempDirPath
  594. );
  595. if(bSuccess == FALSE)
  596. {
  597. dwErrCode = SET_JB_ERROR(jbInstance.GetLastJetError());
  598. SetLastError(dwErrCode);
  599. goto cleanup;
  600. }
  601. }
  602. if(szLogDirPath != NULL)
  603. {
  604. bSuccess = jbInstance.SetSystemParameter(
  605. 0,
  606. JET_paramLogFilePath,
  607. 0,
  608. (unsigned char *)szLogDirPath
  609. );
  610. if(bSuccess == FALSE)
  611. {
  612. dwErrCode = SET_JB_ERROR(jbInstance.GetLastJetError());
  613. SetLastError(dwErrCode);
  614. goto cleanup;
  615. }
  616. }
  617. if( g_EsentMaxCacheSize != LSERVER_PARAMETERS_USE_ESENTDEFAULT )
  618. {
  619. //
  620. // Adjust memory usage, ESENT will failed on invalid parameter
  621. //
  622. bSuccess = jbInstance.SetSystemParameter(
  623. 0,
  624. JET_paramCacheSizeMax,
  625. g_EsentMaxCacheSize,
  626. NULL
  627. );
  628. if(bSuccess == TRUE)
  629. {
  630. bSuccess = jbInstance.SetSystemParameter(
  631. 0,
  632. JET_paramStartFlushThreshold,
  633. g_EsentStartFlushThreshold,
  634. NULL
  635. );
  636. if( bSuccess == TRUE )
  637. {
  638. bSuccess = jbInstance.SetSystemParameter(
  639. 0,
  640. JET_paramStopFlushThreshold,
  641. g_EsentStopFlushThreadhold,
  642. NULL
  643. );
  644. }
  645. }
  646. #if DBG
  647. //
  648. // check build, assert.
  649. //
  650. if(bSuccess == FALSE)
  651. {
  652. dwErrCode = SET_JB_ERROR(jbInstance.GetLastJetError());
  653. TLSASSERT(FALSE);
  654. }
  655. #endif
  656. }
  657. bSuccess = jbInstance.SetSystemParameter( 0, JET_paramDeleteOutOfRangeLogs, 1, NULL);
  658. if(bSuccess == FALSE)
  659. {
  660. dwErrCode = SET_JB_ERROR(jbInstance.GetLastJetError());
  661. SetLastError(dwErrCode);
  662. goto cleanup;
  663. }
  664. //
  665. // We only use single instance for all the work space.
  666. //
  667. if(jbInstance.JBInitJetInstance() == FALSE)
  668. {
  669. LPTSTR pString = NULL;
  670. TLSGetESEError(jbInstance.GetLastJetError(), &pString);
  671. TLSLogEvent(
  672. EVENTLOG_ERROR_TYPE,
  673. TLS_E_DBGENERAL,
  674. TLS_E_INIT_JETBLUE,
  675. jbInstance.GetLastJetError(),
  676. (pString != NULL) ? pString : _TEXT("")
  677. );
  678. if(pString != NULL)
  679. {
  680. LocalFree(pString);
  681. }
  682. DBGPrintf(
  683. DBG_ERROR,
  684. DBG_FACILITY_JETBLUE,
  685. DBGLEVEL_FUNCTION_ERROR,
  686. _TEXT("Init. JetBlue Instance return error code %d\n"),
  687. jbInstance.GetLastJetError()
  688. );
  689. SetLastError(SET_JB_ERROR(jbInstance.GetLastJetError()));
  690. }
  691. cleanup:
  692. return jbInstance.IsSuccess();
  693. }
  694. //--------------------------------------------------------
  695. //
  696. // TLSDbWorkSpace implementation
  697. //
  698. //--------------------------------------------------------
  699. BOOL
  700. __TlsDbWorkSpace::InitWorkSpace(
  701. BOOL bCreateIfNotExist,
  702. LPCTSTR szDatabaseFile,
  703. LPCTSTR szUserName,
  704. LPCTSTR szPassword,
  705. IN LPCTSTR szChkPointDirPath,
  706. IN LPCTSTR szTempDirPath,
  707. IN BOOL bUpdatable
  708. )
  709. /*
  710. */
  711. {
  712. BOOL bSuccess;
  713. DWORD dwErrCode;
  714. //
  715. // Initialize JetBlue Instance
  716. if(g_JbInstance.IsValid() == FALSE)
  717. {
  718. SetLastError(TLS_E_INTERNAL);
  719. bSuccess = FALSE;
  720. goto cleanup;
  721. }
  722. DBGPrintf(
  723. DBG_ERROR,
  724. DBG_FACILITY_JETBLUE,
  725. DBGLEVEL_FUNCTION_ERROR,
  726. _TEXT("InitWorkSpace()...\n")
  727. );
  728. bSuccess = TLSJbInitDatabaseEngine(
  729. m_JetSession,
  730. m_JetDatabase,
  731. szDatabaseFile,
  732. szUserName,
  733. szPassword
  734. );
  735. if(bSuccess == FALSE)
  736. {
  737. goto cleanup;
  738. }
  739. //
  740. // Open all table we need
  741. //
  742. bSuccess = m_LicPackTable.OpenTable(
  743. TRUE,
  744. (bUpdatable) ? JET_bitTableUpdatable : JET_bitTableReadOnly
  745. );
  746. if(bSuccess == FALSE)
  747. {
  748. SetLastError(SET_JB_ERROR(m_LicPackTable.GetLastJetError()));
  749. LPTSTR pString = NULL;
  750. TLSGetESEError(m_LicPackTable.GetLastJetError(), &pString);
  751. TLSLogEvent(
  752. EVENTLOG_ERROR_TYPE,
  753. TLS_E_DBGENERAL,
  754. TLS_E_JB_OPENTABLE,
  755. m_LicPackTable.GetTableName(),
  756. m_LicPackTable.GetLastJetError(),
  757. (pString != NULL) ? pString : _TEXT("")
  758. );
  759. if(pString != NULL)
  760. {
  761. LocalFree(pString);
  762. }
  763. DBGPrintf(
  764. DBG_ERROR,
  765. DBG_FACILITY_JETBLUE,
  766. DBGLEVEL_FUNCTION_ERROR,
  767. _TEXT("Can't open table %s, error code %d\n"),
  768. m_LicPackTable.GetTableName(),
  769. m_LicPackTable.GetLastJetError()
  770. );
  771. goto cleanup;
  772. }
  773. bSuccess = m_LicPackDescTable.OpenTable(
  774. TRUE,
  775. (bUpdatable) ? JET_bitTableUpdatable : JET_bitTableReadOnly
  776. );
  777. if(bSuccess == FALSE)
  778. {
  779. SetLastError(SET_JB_ERROR(m_LicPackDescTable.GetLastJetError()));
  780. LPTSTR pString = NULL;
  781. TLSGetESEError(m_LicPackDescTable.GetLastJetError(), &pString);
  782. TLSLogEvent(
  783. EVENTLOG_ERROR_TYPE,
  784. TLS_E_DBGENERAL,
  785. TLS_E_JB_OPENTABLE,
  786. m_LicPackDescTable.GetTableName(),
  787. m_LicPackDescTable.GetLastJetError(),
  788. (pString != NULL) ? pString : _TEXT("")
  789. );
  790. if(pString != NULL)
  791. {
  792. LocalFree(pString);
  793. }
  794. DBGPrintf(
  795. DBG_ERROR,
  796. DBG_FACILITY_JETBLUE,
  797. DBGLEVEL_FUNCTION_ERROR,
  798. _TEXT("Can't open table %s, error code %d\n"),
  799. m_LicPackDescTable.GetTableName(),
  800. m_LicPackDescTable.GetLastJetError()
  801. );
  802. goto cleanup;
  803. }
  804. bSuccess = m_LicensedTable.OpenTable(
  805. TRUE,
  806. (bUpdatable) ? JET_bitTableUpdatable : JET_bitTableReadOnly
  807. );
  808. if(bSuccess == FALSE)
  809. {
  810. SetLastError(SET_JB_ERROR(m_LicensedTable.GetLastJetError()));
  811. LPTSTR pString = NULL;
  812. TLSGetESEError(m_LicensedTable.GetLastJetError(), &pString);
  813. TLSLogEvent(
  814. EVENTLOG_ERROR_TYPE,
  815. TLS_E_DBGENERAL,
  816. TLS_E_JB_OPENTABLE,
  817. m_LicensedTable.GetTableName(),
  818. m_LicensedTable.GetLastJetError(),
  819. (pString != NULL) ? pString : _TEXT("")
  820. );
  821. if(pString != NULL)
  822. {
  823. LocalFree(pString);
  824. }
  825. DBGPrintf(
  826. DBG_ERROR,
  827. DBG_FACILITY_JETBLUE,
  828. DBGLEVEL_FUNCTION_ERROR,
  829. _TEXT("Can't open table %s, error code %d\n"),
  830. m_LicensedTable.GetTableName(),
  831. m_LicensedTable.GetLastJetError()
  832. );
  833. goto cleanup;
  834. }
  835. cleanup:
  836. return bSuccess;
  837. }