コード例 #1
0
 internal SqlDataReaderSmi(SmiEventStream eventStream, SqlCommand parent, CommandBehavior behavior, SqlInternalConnectionSmi connection, SmiEventSink parentSink) : base(parent, behavior)
 {
     this._eventStream        = eventStream;
     this._currentConnection  = connection;
     this._readerEventSink    = new ReaderEventSink(this, parentSink);
     this._currentPosition    = PositionState.BeforeResults;
     this._isOpen             = true;
     this._indexMap           = null;
     this._visibleColumnCount = 0;
 }
 internal SqlDataReaderSmi(SmiEventStream eventStream, SqlCommand parent, CommandBehavior behavior, SqlInternalConnectionSmi connection, SmiEventSink parentSink) : base(parent, behavior)
 {
     this._eventStream = eventStream;
     this._currentConnection = connection;
     this._readerEventSink = new ReaderEventSink(this, parentSink);
     this._currentPosition = PositionState.BeforeResults;
     this._isOpen = true;
     this._indexMap = null;
     this._visibleColumnCount = 0;
 }
コード例 #3
0
        private SqlInternalConnectionSmi GetContextConnection(SqlConnectionString options, object providerInfo, DbConnection owningConnection)
        {
            SmiContext currentContext             = SmiContextFactory.Instance.GetCurrentContext();
            SqlInternalConnectionSmi contextValue = (SqlInternalConnectionSmi)currentContext.GetContextValue(0);

            if ((contextValue == null) || contextValue.IsConnectionDoomed)
            {
                if (contextValue != null)
                {
                    contextValue.Dispose();
                }
                contextValue = new SqlInternalConnectionSmi(options, currentContext);
                currentContext.SetContextValue(0, contextValue);
            }
            contextValue.Activate();
            return(contextValue);
        }
コード例 #4
0
        private SqlInternalConnectionSmi GetContextConnection(SqlConnectionString options, object providerInfo)
        {
            SmiContext smiContext = SmiContextFactory.Instance.GetCurrentContext();

            SqlInternalConnectionSmi result = (SqlInternalConnectionSmi)smiContext.GetContextValue((int)SmiContextFactory.ContextKey.Connection);

            // context connections are automatically re-useable if they exist unless they've been doomed.
            if (null == result || result.IsConnectionDoomed)
            {
                if (null != result)
                {
                    result.Dispose();   // A doomed connection is a messy thing.  Dispose of it promptly in nearest receptacle.
                }

                result = new SqlInternalConnectionSmi(options, smiContext);
                smiContext.SetContextValue((int)SmiContextFactory.ContextKey.Connection, result);
            }

            result.Activate();

            return(result);
        }
コード例 #5
0
        private SqlInternalConnectionSmi GetContextConnection(SqlConnectionString options, object providerInfo) {
            SmiContext smiContext = SmiContextFactory.Instance.GetCurrentContext();

            SqlInternalConnectionSmi result = (SqlInternalConnectionSmi)smiContext.GetContextValue((int)SmiContextFactory.ContextKey.Connection);

            // context connections are automatically re-useable if they exist unless they've been doomed.
            if (null == result || result.IsConnectionDoomed) {
                if (null != result) {
                    result.Dispose();   // A doomed connection is a messy thing.  Dispose of it promptly in nearest receptacle.
                }

                result = new SqlInternalConnectionSmi(options, smiContext);
                smiContext.SetContextValue((int)SmiContextFactory.ContextKey.Connection, result);
            }

            result.Activate();

            return result;
        }
コード例 #6
0
        private void SetUpSmiRequest(SqlInternalConnectionSmi innerConnection)
        {
            this.DisposeSmiRequest();
            if (this.Notification != null)
            {
                throw SQL.NotificationsNotAvailableOnContextConnection();
            }
            SmiParameterMetaData[] parameterMetaData = null;
            ParameterPeekAheadValue[] valueArray = null;
            int parameterCount = this.GetParameterCount(this.Parameters);
            if (0 < parameterCount)
            {
                parameterMetaData = new SmiParameterMetaData[parameterCount];
                valueArray = new ParameterPeekAheadValue[parameterCount];
                for (int j = 0; j < parameterCount; j++)
                {
                    SqlParameter parameter2 = this.Parameters[j];
                    parameter2.Validate(j, System.Data.CommandType.StoredProcedure == this.CommandType);
                    parameterMetaData[j] = parameter2.MetaDataForSmi(out valueArray[j]);
                    if (!innerConnection.IsKatmaiOrNewer)
                    {
                        MetaType metaTypeFromSqlDbType = MetaType.GetMetaTypeFromSqlDbType(parameterMetaData[j].SqlDbType, parameterMetaData[j].IsMultiValued);
                        if (!metaTypeFromSqlDbType.Is90Supported)
                        {
                            throw ADP.VersionDoesNotSupportDataType(metaTypeFromSqlDbType.TypeName);
                        }
                    }
                }
            }
            System.Data.CommandType commandType = this.CommandType;
            this._smiRequestContext = innerConnection.InternalContext;
            this._smiRequest = this._smiRequestContext.CreateRequestExecutor(this.CommandText, commandType, parameterMetaData, this.EventSink);
            this.EventSink.ProcessMessagesAndThrow();
            for (int i = 0; i < parameterCount; i++)
            {
                if ((ParameterDirection.Output == parameterMetaData[i].Direction) || (ParameterDirection.ReturnValue == parameterMetaData[i].Direction))
                {
                    continue;
                }
                SqlParameter parameter = this.Parameters[i];
                object coercedValue = parameter.GetCoercedValue();
                ExtendedClrTypeCode typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType(parameterMetaData[i].SqlDbType, parameterMetaData[i].IsMultiValued, coercedValue, null, SmiContextFactory.Instance.NegotiatedSmiVersion);
                if ((System.Data.CommandType.StoredProcedure == commandType) && (ExtendedClrTypeCode.Empty == typeCode))
                {
                    this._smiRequest.SetDefault(i);
                    continue;
                }
                int size = parameter.Size;
                if (((size != 0) && (size != -1L)) && !parameter.SizeInferred)
                {
                    switch (parameterMetaData[i].SqlDbType)
                    {
                        case SqlDbType.NText:
                            if (size != 0x3fffffff)
                            {
                                throw SQL.ParameterSizeRestrictionFailure(i);
                            }
                            break;

                        case SqlDbType.NVarChar:
                            if (((size > 0) && (size != 0x3fffffff)) && (parameterMetaData[i].MaxLength == -1L))
                            {
                                throw SQL.ParameterSizeRestrictionFailure(i);
                            }
                            break;

                        case SqlDbType.Text:
                        case SqlDbType.Image:
                            goto Label_01E8;

                        case SqlDbType.Timestamp:
                            if (size < SmiMetaData.DefaultTimestamp.MaxLength)
                            {
                                throw SQL.ParameterSizeRestrictionFailure(i);
                            }
                            break;

                        case SqlDbType.VarBinary:
                        case SqlDbType.VarChar:
                            goto Label_020C;

                        case SqlDbType.Variant:
                            goto Label_0271;

                        case SqlDbType.Xml:
                            if ((coercedValue != null) && (ExtendedClrTypeCode.SqlXml != typeCode))
                            {
                                throw SQL.ParameterSizeRestrictionFailure(i);
                            }
                            break;
                    }
                }
                goto Label_02CF;
            Label_01E8:
                if (size == 0x7fffffff)
                {
                    goto Label_02CF;
                }
                throw SQL.ParameterSizeRestrictionFailure(i);
            Label_020C:
                if (((size <= 0) || (size == 0x7fffffff)) || (parameterMetaData[i].MaxLength != -1L))
                {
                    goto Label_02CF;
                }
                throw SQL.ParameterSizeRestrictionFailure(i);
            Label_0271:
                if (coercedValue != null)
                {
                    MetaType metaTypeFromValue = MetaType.GetMetaTypeFromValue(coercedValue);
                    if (((metaTypeFromValue.IsNCharType && (size < 0xfa0L)) || (metaTypeFromValue.IsBinType && (size < 0x1f40L))) || (metaTypeFromValue.IsAnsiType && (size < 0x1f40L)))
                    {
                        throw SQL.ParameterSizeRestrictionFailure(i);
                    }
                }
            Label_02CF:
                if (innerConnection.IsKatmaiOrNewer)
                {
                    ValueUtilsSmi.SetCompatibleValueV200(this.EventSink, this._smiRequest, i, parameterMetaData[i], coercedValue, typeCode, parameter.Offset, parameter.Size, valueArray[i]);
                }
                else
                {
                    ValueUtilsSmi.SetCompatibleValue(this.EventSink, this._smiRequest, i, parameterMetaData[i], coercedValue, typeCode, parameter.Offset);
                }
            }
        }
コード例 #7
0
 internal EventSink(SqlInternalConnectionSmi connection)
 {
     Debug.Assert(null != connection, "null connection?");
     _connection = connection;
 }
 internal EventSink(SqlInternalConnectionSmi connection)
 {
     this._connection = connection;
 }
コード例 #9
0
 internal EventSink(SqlInternalConnectionSmi connection) {
     Debug.Assert(null != connection, "null connection?");
     _connection = connection;
 }
コード例 #10
0
 public override void Open()
 {
     IntPtr ptr;
     Bid.ScopeEnter(out ptr, "<sc.SqlConnection.Open|API> %d#", this.ObjectID);
     try
     {
         if (this.StatisticsEnabled)
         {
             if (this._statistics == null)
             {
                 this._statistics = new SqlStatistics();
             }
             else
             {
                 this._statistics.ContinueOnNewConnection();
             }
         }
         SNIHandle target = null;
         SqlStatistics statistics = null;
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
             statistics = SqlStatistics.StartTimer(this.Statistics);
             this.InnerConnection.OpenConnection(this, this.ConnectionFactory);
             target = SqlInternalConnection.GetBestEffortCleanupTarget(this);
             SqlInternalConnectionSmi innerConnection = this.InnerConnection as SqlInternalConnectionSmi;
             if (innerConnection != null)
             {
                 innerConnection.AutomaticEnlistment();
             }
             else
             {
                 if (this.StatisticsEnabled)
                 {
                     ADP.TimerCurrent(out this._statistics._openTimestamp);
                     this.Parser.Statistics = this._statistics;
                 }
                 else
                 {
                     this.Parser.Statistics = null;
                     this._statistics = null;
                 }
                 this.CompleteOpen();
             }
         }
         catch (OutOfMemoryException exception3)
         {
             this.Abort(exception3);
             throw;
         }
         catch (StackOverflowException exception2)
         {
             this.Abort(exception2);
             throw;
         }
         catch (ThreadAbortException exception)
         {
             this.Abort(exception);
             SqlInternalConnection.BestEffortCleanup(target);
             throw;
         }
         finally
         {
             SqlStatistics.StopTimer(statistics);
         }
     }
     finally
     {
         Bid.ScopeLeave(ref ptr);
     }
 }
コード例 #11
0
 internal EventSink(SqlInternalConnectionSmi connection)
 {
     this._connection = connection;
 }