IsolationLevel および Mode プロパティの例 (vc++)IsolationLevel and Mode Properties Example (VC++)

この例では、モード、排他的な接続を開き、プロパティ、およびIsolationLevelを他のトランザクションの分離を実行したトランザクションを開きます。This example uses the Mode property to open an exclusive connection, and the IsolationLevel property to open a transaction that is conducted in isolation of other transactions.


// BeginIsolationLevelCpp.cpp  
// compile with: /EHsc  
#import "msado15.dll" no_namespace rename("EOF","EndOfFile")  
#include <ole2.h>  
#include <stdio.h>  
#include <conio.h>  
#include "icrsint.h"  
// This class extracts titles and type from Title table  
class CTitleRs : public CADORecordBinding {  
   // Column title is the 2nd field in the table  
    ADO_VARIABLE_LENGTH_ENTRY2(2, adVarChar, m_szau_Title, sizeof(m_szau_Title), lau_TitleStatus, FALSE)  
   // Column type is the 3rd field in the table  
   ADO_VARIABLE_LENGTH_ENTRY2(3, adVarChar, m_szau_Type, sizeof(m_szau_Type), lau_TypeStatus, TRUE)  
   CHAR m_szau_Title[81];  
   ULONG lau_TitleStatus;  
   CHAR m_szau_Type[13];  
   ULONG lau_TypeStatus;  
// Function Declarations  
inline void TESTHR(HRESULT x) { if FAILED(x) _com_issue_error(x); };  
void IsolationLevelX();  
void PrintProviderError(_ConnectionPtr pConnection);  
void PrintComError(_com_error &e);  
int main() {  
   if (FAILED(::CoInitialize(NULL)))  
      return -1;  
void IsolationLevelX() {  
   // Define ADO ObjectPointers.  Initialize Pointers on define.  These are in the ADODB :: namespace.  
   _RecordsetPtr  pRstTitles  = NULL;  
   _ConnectionPtr pConnection = NULL;  
   // Define other Variables  
   HRESULT hr = S_OK;  
   IADORecordBinding *picRs = NULL;   // Interface Pointer Declared  
   CTitleRs titlers;   // C++ Class Object  
   LPSTR p_TempStr = NULL;  
   char * token1;  
   // Assign Connection String to Variable  
   _bstr_t strCnn("Provider='sqloledb'; Data Source='My_Data_Source'; Initial Catalog='pubs'; Integrated Security='SSPI';");  
   try {  
      // Open Connection and Titles Table  
      pConnection->Mode = adModeShareExclusive;  
      pConnection->IsolationLevel = adXactIsolated;  
      pConnection->Open(strCnn,"", "", adConnectUnspecified);  
      pRstTitles->CursorType = adOpenDynamic;  
      pRstTitles->LockType = adLockPessimistic;  
      pRstTitles->Open("titles", _variant_t((IDispatch*) pConnection, true),  
                       adOpenDynamic, adLockPessimistic, adCmdTable);  
      // Display Connection Mode  
      if (pConnection->Mode == adModeShareExclusive)  
         printf("Connection Mode Is Exclusive");  
         printf("Connection Mode Is Not Exclusive");       
      // Display Isolation Level   
      if (pConnection->IsolationLevel == adXactIsolated)  
         printf("\nTransaction is Isolated\n");  
         printf("\nTransaction is not Isolated\n");  
      // Open an IADORecordBinding interface pointer which we will use for binding Recordset to a class.  
      TESTHR(pRstTitles->QueryInterface( __uuidof(IADORecordBinding), (LPVOID*)&picRs));  
      // Bind the Recordset to a C++ class here  
      // Change the type of psychology titles.  
      p_TempStr = (LPSTR) malloc(sizeof(titlers.m_szau_Type));  
      while (!(pRstTitles->EndOfFile)) {  
         // Set the final character of the destination string to NULL.  
         p_TempStr[sizeof(titlers.m_szau_Type) - 1] = '\0';  
         // The source string will get truncated if its length is   
         // longer than the length of the destination string minus one.  
         strncpy_s(p_TempStr, sizeof(titlers.m_szau_Type), strtok_s(titlers.m_szau_Type, " ", &token1), sizeof(titlers.m_szau_Type) - 1);  
         // Compare type with psychology  
         if (!strcmp(p_TempStr,"psychology")) {  
            // Set the final character of the destination string to NULL.  
            titlers.m_szau_Type[sizeof(titlers.m_szau_Type) - 1] = '\0';  
            // Copy "self_help" title field.  The source string will get truncated if its length is   
            // longer than the length of the destination string minus one.  
            strncpy_s(titlers.m_szau_Type, sizeof(titlers.m_szau_Type), "self_help", sizeof(titlers.m_szau_Type) - 1);  
      // Print current data in recordset.  
      // Open again IADORecordBinding interface pointer for Binding   
      // Recordset to a class.  
      TESTHR(pRstTitles->QueryInterface(__uuidof(IADORecordBinding), (LPVOID*)&picRs));  
      // ReBinding the Recordset to a C++ Class  
      // Move to the first record of the title table  
      // Clear the screen for the next display  
      // system("cls");  
      while (!pRstTitles->EndOfFile) {  
         printf("%s -  %s\n",titlers.lau_TitleStatus == adFldOK ?   
            titlers.m_szau_Title :"<NULL>",  
            titlers.lau_TypeStatus == adFldOK ?   
            titlers.m_szau_Type :"<NULL>");  
   catch(_com_error &e) {  
      // Notify the user of errors if any.  
   // Clean up objects before exit.  Release the IADORecordset Interface here.  
   if (picRs)  
   if (pRstTitles)  
      if (pRstTitles->State == adStateOpen)  
   if (pConnection)  
      if (pConnection->State == adStateOpen) {  
         // Restore Original Data  
   // Deallocate the memory  
   if (p_TempStr)  
void PrintProviderError(_ConnectionPtr pConnection) {  
   // Print Provider Errors from Connection object  
   // pErr is a record object in the Connection's Error collection  
   ErrorPtr pErr = NULL;  
   if ((pConnection->Errors->Count)>0) {  
      long nCount = pConnection->Errors->Count;  
      // Collection ranges from 0 to nCount-1  
      for (long i = 0 ; i < nCount ; i++) {  
         pErr = pConnection->Errors->GetItem(i);  
         printf("\t Error Number :%x \t %s",pErr->Number, (LPCSTR) pErr->Description);  
void PrintComError(_com_error &e) {  
   _bstr_t bstrSource(e.Source());  
   _bstr_t bstrDescription(e.Description());  
   // Print Com errors.  
   printf("\tCode = %08lx\n", e.Error());  
   printf("\tCode meaning = %s\n", e.ErrorMessage());  
   printf("\tSource = %s\n", (LPCSTR) bstrSource);  
   printf("\tDescription = %s\n", (LPCSTR) bstrDescription);  

接続モードは排他的Connection Mode Is Exclusive
トランザクション分離Transaction is Isolated
データベースのビジー状態 Executive のガイド - ビジネスThe Busy Executive's Database Guide - business
コンピューターと料理。その貸借対照表のビジネスCooking with Computers: Surreptitious Balance Sheets - business
コンピューターの負荷に対処することができます!-ビジネスYou Can Combat Computer Stress! - business
コンピューター - ビジネスについての直接の説明Straight Talk About Computers - business
シリコン バレー Gastronomic 扱います - mod_cookSilicon Valley Gastronomic Treats - mod_cook
Gourmet 電子レンジ - mod_cookThe Gourmet Microwave - mod_cook
コンピューターの料理 - 決心についていないユーザーの心理状態The Psychology of Computer Cooking - UNDECIDED
ですがユーザー フレンドリですか。-popular_compBut Is It User Friendly? - popular_comp
シリコン バレー - popular_comp のシークレットSecrets of Silicon Valley - popular_comp
Net エチケット - popular_compNet Etiquette - popular_comp
コンピューターの Phobic と非他者と個人:動作のバリエーションの self_helpComputer Phobic AND Non-Phobic Individuals: Behavior Variations - self_help
怒りの敵ですか。-self_helpIs Anger the Enemy? - self_help
-Self_help を与えることがなく有効期間Life Without Fear - self_help
長期にわたるデータ Deprivation:次の 4 つのケース スタディ - self_helpProlonged Data Deprivation: Four Case Studies - self_help
感情的なセキュリティ:新しいアルゴリズムの self_helpEmotional Security: A New Algorithm - self_help
タマネギ、Leeks とガーリック トースト:地中海 - trad_cook の料理のシークレットOnions, Leeks, and Garlic: Cooking Secrets of the Mediterranean - trad_cook
バッキンガム Palace 台所 - trad_cook で 50 年Fifty Years in Buckingham Palace Kitchens - trad_cook
寿司、すべてのユーザーですか?-trad_cookSushi, Anyone? - trad_cook

関連項目See Also

IsolationLevel プロパティ IsolationLevel Property
Mode プロパティ (ADO)Mode Property (ADO)