当前位置: 首页>>代码示例>>C#>>正文


C# TdsParserStateObject.ExecuteFlush方法代码示例

本文整理汇总了C#中System.Data.SqlClient.TdsParserStateObject.ExecuteFlush方法的典型用法代码示例。如果您正苦于以下问题:C# TdsParserStateObject.ExecuteFlush方法的具体用法?C# TdsParserStateObject.ExecuteFlush怎么用?C# TdsParserStateObject.ExecuteFlush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.TdsParserStateObject的用法示例。


在下文中一共展示了TdsParserStateObject.ExecuteFlush方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TdsExecuteRPC


//.........这里部分代码省略.........
                                    {
                                        completion = new TaskCompletionSource<object>();
                                        task = completion.Task;
                                    }

                                    AsyncHelper.ContinueTask(writeParamTask, completion,
                                      () => TdsExecuteRPC(rpcArray, timeout, inSchema, stateObj, isCommandProc, sync, completion,
                                                            startRpc: ii, startParam: i + 1),
                                        connectionToDoom: _connHandler,
                                        onFailure: exc => TdsExecuteRPC_OnFailure(exc, stateObj));

                                    // Take care of releasing the locks
                                    if (releaseConnectionLock)
                                    {
                                        task.ContinueWith(_ =>
                                        {
                                            _connHandler._parserLock.Release();
                                        }, TaskScheduler.Default);
                                        releaseConnectionLock = false;
                                    }

                                    return task;
                                }
                            }
#if DEBUG
                            else
                            {
                                Debug.Assert(writeParamTask == null, "Should not have a task when executing sync");
                            }
#endif
                        } // parameter for loop

                        // If this is not the last RPC we are sending, add the batch flag
                        if (ii < (rpcArray.Length - 1))
                        {
                            stateObj.WriteByte(TdsEnums.YUKON_RPCBATCHFLAG);
                        }
                    } // rpc for loop

                    Task execFlushTask = stateObj.ExecuteFlush();
                    Debug.Assert(!sync || execFlushTask == null, "Should not get a task when executing sync");
                    if (execFlushTask != null)
                    {
                        Task task = null;

                        if (completion == null)
                        {
                            completion = new TaskCompletionSource<object>();
                            task = completion.Task;
                        }

                        bool taskReleaseConnectionLock = releaseConnectionLock;
                        execFlushTask.ContinueWith(tsk => ExecuteFlushTaskCallback(tsk, stateObj, completion, taskReleaseConnectionLock), TaskScheduler.Default);

                        // ExecuteFlushTaskCallback will take care of the locks for us
                        releaseConnectionLock = false;

                        return task;
                    }
                }
                catch (Exception e)
                {
                    if (!ADP.IsCatchableExceptionType(e))
                    {
                        throw;
                    }

                    FailureCleanup(stateObj, e);

                    throw;
                }
                FinalizeExecuteRPC(stateObj);
                if (completion != null)
                {
                    completion.SetResult(null);
                }
                return null;
            }
            catch (Exception e)
            {
                FinalizeExecuteRPC(stateObj);
                if (completion != null)
                {
                    completion.SetException(e);
                    return null;
                }
                else
                {
                    throw e;
                }
            }
            finally
            {
                Debug.Assert(firstCall || !releaseConnectionLock, "Shouldn't be releasing locks synchronously after the first call");
                if (releaseConnectionLock)
                {
                    _connHandler._parserLock.Release();
                }
            }
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:101,代码来源:TdsParser.cs

示例2: TdsExecuteSQLBatch

        internal Task TdsExecuteSQLBatch(string text, int timeout, TdsParserStateObject stateObj, bool sync, bool callerHasConnectionLock = false)
        {
            if (TdsParserState.Broken == State || TdsParserState.Closed == State)
            {
                return null;
            }

            if (stateObj.BcpLock)
            {
                throw SQL.ConnectionLockedForBcpEvent();
            }

            // Promote, Commit and Rollback requests for
            // delegated transactions often happen while there is an open result
            // set, so we need to handle them by using a different MARS session, 
            // otherwise we'll write on the physical state objects while someone
            // else is using it.  When we don't have MARS enabled, we need to 
            // lock the physical state object to syncronize it's use at least 
            // until we increment the open results count.  Once it's been 
            // incremented the delegated transaction requests will fail, so they
            // won't stomp on anything.

            // Only need to take the lock if neither the thread nor the caller claims to already have it
            bool needToTakeParserLock = (!callerHasConnectionLock) && (!_connHandler.ThreadHasParserLockForClose);
            Debug.Assert(!_connHandler.ThreadHasParserLockForClose || sync, "Thread shouldn't claim to have the parser lock if we are doing async writes");     // Since we have the possibility of pending with async writes, make sure the thread doesn't claim to already have the lock
            Debug.Assert(needToTakeParserLock || _connHandler._parserLock.ThreadMayHaveLock(), "Thread or caller claims to have connection lock, but lock is not taken");

            bool releaseConnectionLock = false;
            if (needToTakeParserLock)
            {
                _connHandler._parserLock.Wait(canReleaseFromAnyThread: !sync);
                releaseConnectionLock = true;
            }

            // Switch the writing mode
            // NOTE: We are not turning off async writes when we complete since SqlBulkCopy uses this method and expects _asyncWrite to not change
            _asyncWrite = !sync;

            try
            {
                // Check that the connection is still alive
                if ((_state == TdsParserState.Closed) || (_state == TdsParserState.Broken))
                {
                    throw ADP.ClosedConnectionError();
                }


                stateObj.SetTimeoutSeconds(timeout);
                stateObj.SniContext = SniContext.Snix_Execute;

                WriteRPCBatchHeaders(stateObj);

                stateObj._outputMessageType = TdsEnums.MT_SQL;

                WriteString(text, text.Length, 0, stateObj);

                Task executeTask = stateObj.ExecuteFlush();
                if (executeTask == null)
                {
                    stateObj.SniContext = SniContext.Snix_Read;
                }
                else
                {
                    Debug.Assert(!sync, "Should not have gotten a Task when writing in sync mode");

                    // Need to wait for flush - continuation will unlock the connection                    
                    bool taskReleaseConnectionLock = releaseConnectionLock;
                    releaseConnectionLock = false;
                    return executeTask.ContinueWith(t =>
                    {
                        Debug.Assert(!t.IsCanceled, "Task should not be canceled");
                        try
                        {
                            if (t.IsFaulted)
                            {
                                FailureCleanup(stateObj, t.Exception.InnerException);
                                throw t.Exception.InnerException;
                            }
                            else
                            {
                                stateObj.SniContext = SniContext.Snix_Read;
                            }
                        }
                        finally
                        {
                            if (taskReleaseConnectionLock)
                            {
                                _connHandler._parserLock.Release();
                            }
                        }
                    }, TaskScheduler.Default);
                }

                // Finished sync
                return null;
            }
            catch (Exception e)
            {
                if (!ADP.IsCatchableExceptionType(e))
                {
//.........这里部分代码省略.........
开发者ID:nnyamhon,项目名称:corefx,代码行数:101,代码来源:TdsParser.cs

示例3: TdsExecuteSQLBatch

 internal void TdsExecuteSQLBatch(string text, int timeout, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj)
 {
     if ((TdsParserState.Broken != this.State) && (this.State != TdsParserState.Closed))
     {
         if (stateObj.BcpLock)
         {
             throw SQL.ConnectionLockedForBcpEvent();
         }
         bool lockTaken = false;
         lock (this._connHandler)
         {
             try
             {
                 if (this._isYukon && !this.MARSOn)
                 {
                     Monitor.Enter(this._physicalStateObj, ref lockTaken);
                 }
                 this._connHandler.CheckEnlistedTransactionBinding();
                 stateObj.SetTimeoutSeconds(timeout);
                 if (!this._fMARS && this._physicalStateObj.HasOpenResult)
                 {
                     Bid.Trace("<sc.TdsParser.TdsExecuteSQLBatch|ERR> Potential multi-threaded misuse of connection, non-MARs connection with an open result %d#\n", this.ObjectID);
                 }
                 stateObj.SniContext = SniContext.Snix_Execute;
                 if (this._isYukon)
                 {
                     this.WriteMarsHeader(stateObj, this.CurrentTransaction);
                     if (notificationRequest != null)
                     {
                         this.WriteQueryNotificationHeader(notificationRequest, stateObj);
                     }
                 }
                 stateObj._outputMessageType = 1;
                 this.WriteString(text, text.Length, 0, stateObj);
                 stateObj.ExecuteFlush();
                 stateObj.SniContext = SniContext.Snix_Read;
             }
             catch (Exception exception)
             {
                 if (!ADP.IsCatchableExceptionType(exception))
                 {
                     throw;
                 }
                 this.FailureCleanup(stateObj, exception);
                 throw;
             }
             finally
             {
                 if (lockTaken)
                 {
                     Monitor.Exit(this._physicalStateObj);
                 }
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:56,代码来源:TdsParser.cs

示例4: TdsExecuteRPC


//.........这里部分代码省略.........
                          if (!sync) {
                              if (writeParamTask == null) {
                                  writeParamTask = stateObj.WaitForAccumulatedWrites();                             
                              }

                              if (writeParamTask != null) {
                                  Task task = null;
                                  if (completion == null) {
                                      completion = new TaskCompletionSource<object>();
                                      task = completion.Task;
                                  }

                                  AsyncHelper.ContinueTask(writeParamTask, completion,
                                      () => TdsExecuteRPC(cmd, rpcArray, timeout, inSchema, notificationRequest, stateObj, isCommandProc, sync, completion,
                                                            startRpc: ii, startParam: i + 1),
                                      connectionToDoom: _connHandler,
                                      onFailure: exc => TdsExecuteRPC_OnFailure(exc, stateObj));

                                  // Take care of releasing the locks
                                  if (releaseConnectionLock) {
                                      task.ContinueWith(_ => {
                                          _connHandler._parserLock.Release();
                                      }, TaskScheduler.Default);
                                      releaseConnectionLock = false;
                                  }

                                  return task;
                              }
                          }
#if DEBUG
                          else {
                              Debug.Assert(writeParamTask == null, "Should not have a task when executing sync");
                          }
#endif
                      } // parameter for loop

                      // If this is not the last RPC we are sending, add the batch flag
                      if (ii < (rpcArray.Length - 1)) {
                          if (_isYukon) {
                              stateObj.WriteByte(TdsEnums.YUKON_RPCBATCHFLAG);

                          }
                          else {
                              stateObj.WriteByte(TdsEnums.SHILOH_RPCBATCHFLAG);
                          }
                      }
                  } // rpc for loop

                  Task execFlushTask = stateObj.ExecuteFlush();
                  Debug.Assert(!sync || execFlushTask == null, "Should not get a task when executing sync");
                  if (execFlushTask != null) {
                      Task task = null;

                      if (completion == null) {
                          completion = new TaskCompletionSource<object>();
                          task = completion.Task;
                      }

                      bool taskReleaseConnectionLock = releaseConnectionLock;
                      execFlushTask.ContinueWith(tsk => ExecuteFlushTaskCallback(tsk, stateObj, completion, taskReleaseConnectionLock), TaskScheduler.Default);
                      
                      // ExecuteFlushTaskCallback will take care of the locks for us
                      releaseConnectionLock = false;
                      
                      return task;
                  }                  
              }
              catch (Exception e) {
                  // 
                  if (!ADP.IsCatchableExceptionType(e)) {
                      throw;
                  }

                  FailureCleanup(stateObj, e);

                  throw;
              }
              FinalizeExecuteRPC(stateObj);
              if (completion != null) {
                  completion.SetResult(null);
              }
              return null;
          }
          catch (Exception e) {
              FinalizeExecuteRPC(stateObj);
              if (completion != null) {
                  completion.SetException(e);
                  return null;
              }
              else {
                  throw e;
              }
          }
          finally {
              Debug.Assert(firstCall || !releaseConnectionLock, "Shouldn't be releasing locks synchronously after the first call");
              if (releaseConnectionLock) {
                  _connHandler._parserLock.Release();
              }
          }
      }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:101,代码来源:TdsParser.cs

示例5: TdsExecuteRPC


//.........这里部分代码省略.........
                                         this.WriteByte(1, stateObj);
                                         if ((param.XmlSchemaCollectionDatabase != null) && (param.XmlSchemaCollectionDatabase != ADP.StrEmpty))
                                         {
                                             length = param.XmlSchemaCollectionDatabase.Length;
                                             this.WriteByte((byte) length, stateObj);
                                             this.WriteString(param.XmlSchemaCollectionDatabase, length, 0, stateObj);
                                         }
                                         else
                                         {
                                             this.WriteByte(0, stateObj);
                                         }
                                         if ((param.XmlSchemaCollectionOwningSchema != null) && (param.XmlSchemaCollectionOwningSchema != ADP.StrEmpty))
                                         {
                                             length = param.XmlSchemaCollectionOwningSchema.Length;
                                             this.WriteByte((byte) length, stateObj);
                                             this.WriteString(param.XmlSchemaCollectionOwningSchema, length, 0, stateObj);
                                         }
                                         else
                                         {
                                             this.WriteByte(0, stateObj);
                                         }
                                         if ((param.XmlSchemaCollectionName != null) && (param.XmlSchemaCollectionName != ADP.StrEmpty))
                                         {
                                             length = param.XmlSchemaCollectionName.Length;
                                             this.WriteShort((short) length, stateObj);
                                             this.WriteString(param.XmlSchemaCollectionName, length, 0, stateObj);
                                         }
                                         else
                                         {
                                             this.WriteShort(0, stateObj);
                                         }
                                     }
                                     else
                                     {
                                         this.WriteByte(0, stateObj);
                                     }
                                 }
                                 else if (this._isShiloh && internalMetaType.IsCharType)
                                 {
                                     SqlCollation collation = (param.Collation != null) ? param.Collation : this._defaultCollation;
                                     this.WriteUnsignedInt(collation.info, stateObj);
                                     this.WriteByte(collation.sortId, stateObj);
                                 }
                                 if (size == 0)
                                 {
                                     this.WriteParameterVarLen(internalMetaType, actualSize, isNull, stateObj);
                                 }
                                 else
                                 {
                                     this.WriteParameterVarLen(internalMetaType, size, isNull, stateObj);
                                 }
                                 if (!isNull)
                                 {
                                     if (flag2)
                                     {
                                         this.WriteSqlValue(coercedValue, internalMetaType, actualSize, size, param.Offset, stateObj);
                                     }
                                     else
                                     {
                                         this.WriteValue(coercedValue, internalMetaType, param.GetActualScale(), actualSize, size, param.Offset, stateObj);
                                     }
                                 }
                             Label_080A:;
                             }
                         }
                     }
                     if (i < (rpcArray.Length - 1))
                     {
                         if (this._isYukon)
                         {
                             this.WriteByte(0xff, stateObj);
                         }
                         else
                         {
                             this.WriteByte(0x80, stateObj);
                         }
                     }
                 }
                 stateObj.ExecuteFlush();
                 stateObj.SniContext = SniContext.Snix_Read;
             }
             catch (Exception exception)
             {
                 if (!ADP.IsCatchableExceptionType(exception))
                 {
                     throw;
                 }
                 this.FailureCleanup(stateObj, exception);
                 throw;
             }
             finally
             {
                 if (lockTaken)
                 {
                     Monitor.Exit(this._physicalStateObj);
                 }
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:TdsParser.cs


注:本文中的System.Data.SqlClient.TdsParserStateObject.ExecuteFlush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。