示例#1
0
        static public void DeriveParameters(SqlCommand command)   // MDAC 65927\
        {
            SqlConnection.ExecutePermission.Demand();

            if (null == command)
            {
                throw ADP.ArgumentNull("command");
            }
            TdsParser bestEffortCleanupTarget = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try {
#if DEBUG
                TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();

                RuntimeHelpers.PrepareConstrainedRegions();
                try {
                    tdsReliabilitySection.Start();
#else
                {
#endif
                    bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(command.Connection);
                    command.DeriveParameters();
                }
#if DEBUG
                finally {
                    tdsReliabilitySection.Stop();
                }
#endif
            }
            catch (System.OutOfMemoryException e) {
                if (null != command && null != command.Connection)
                {
                    command.Connection.Abort(e);
                }
                throw;
            }
            catch (System.StackOverflowException e) {
                if (null != command && null != command.Connection)
                {
                    command.Connection.Abort(e);
                }
                throw;
            }
            catch (System.Threading.ThreadAbortException e)  {
                if (null != command && null != command.Connection)
                {
                    command.Connection.Abort(e);
                }
                SqlInternalConnection.BestEffortCleanup(bestEffortCleanupTarget);
                throw;
            }
        }
示例#2
0
 public int Fill(DataTable dataTable, object ADODBRecordSet)
 {
     if (null == dataTable)
     {
         throw ADP.ArgumentNull("dataTable");
     }
     if (null == ADODBRecordSet)
     {
         throw ADP.ArgumentNull("adodb");
     }
     return(FillFromADODB((object)dataTable, ADODBRecordSet, null, false));
 }
示例#3
0
 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
 {
     if (null == destinationType)
     {
         throw ADP.ArgumentNull("destinationType");
     }
     if ((typeof(System.ComponentModel.Design.Serialization.InstanceDescriptor) == destinationType) && (value is OleDbParameter))
     {
         return(ConvertToInstanceDescriptor(value as OleDbParameter));
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
示例#4
0
 public override object?ConvertTo(ITypeDescriptorContext?context, CultureInfo?culture, object?value, Type destinationType)
 {
     if (destinationType == null)
     {
         throw ADP.ArgumentNull("destinationType");
     }
     if ((destinationType == typeof(string)) && (value != null) && (value is int))
     {
         return(ODB.ELookup((OleDbHResult)value));
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
示例#5
0
        //
        // Public methods
        //
        public void ExecuteAndSend(SqlCommand command)
        {
            SetPipeBusy( );
            try {
                EnsureNormalSendValid("ExecuteAndSend");

                if (null == command)
                {
                    throw ADP.ArgumentNull("command");
                }

                SqlConnection connection = command.Connection;

                // if the command doesn't have a connection set up, try to set one up on it's behalf
                if (null == connection)
                {
                    using (SqlConnection newConnection = new SqlConnection("Context Connection=true")) {
                        newConnection.Open( );

                        // use try-finally to restore command's connection property to it's original state
                        try {
                            command.Connection = newConnection;
                            command.ExecuteToPipe(_smiContext);
                        }
                        finally {
                            command.Connection = null;
                        }
                    }
                }
                else
                {
                    // validate connection state
                    if (ConnectionState.Open != connection.State)
                    {
                        throw ADP.ClosedConnectionError();
                    }

                    // validate connection is current scope's connection
                    SqlInternalConnectionSmi internalConnection = connection.InnerConnection as SqlInternalConnectionSmi;

                    if (null == internalConnection)
                    {
                        throw SQL.SqlPipeCommandHookedUpToNonContextConnection( );
                    }

                    command.ExecuteToPipe(_smiContext);
                }
            }
            finally {
                ClearPipeBusy( );
            }
        }
示例#6
0
 public int GetOrdinal(string fieldName)
 {
     if (null == fieldName)
     {
         throw ADP.ArgumentNull(nameof(fieldName));
     }
     int index = IndexOf(fieldName);
     if (-1 == index)
     {
         throw ADP.IndexOutOfRange(fieldName);
     }
     return index;
 }
        public static void DeriveParameters(OdbcCommand command)
        {
            OdbcConnection.ExecutePermission.Demand();
            if (command == null)
            {
                throw ADP.ArgumentNull("command");
            }
            CommandType commandType = command.CommandType;

            if (commandType == CommandType.Text)
            {
                throw ADP.DeriveParametersNotSupported(command);
            }
            if (commandType != CommandType.StoredProcedure)
            {
                if (commandType == CommandType.TableDirect)
                {
                    throw ADP.DeriveParametersNotSupported(command);
                }
                throw ADP.InvalidCommandType(command.CommandType);
            }
            if (ADP.IsEmpty(command.CommandText))
            {
                throw ADP.CommandTextRequired("DeriveParameters");
            }
            OdbcConnection connection = command.Connection;

            if (connection == null)
            {
                throw ADP.ConnectionRequired("DeriveParameters");
            }
            ConnectionState state = connection.State;

            if (ConnectionState.Open != state)
            {
                throw ADP.OpenConnectionRequired("DeriveParameters", state);
            }
            OdbcParameter[]         parameterArray = DeriveParametersFromStoredProcedure(connection, command);
            OdbcParameterCollection parameters     = command.Parameters;

            parameters.Clear();
            int length = parameterArray.Length;

            if (0 < length)
            {
                for (int i = 0; i < parameterArray.Length; i++)
                {
                    parameters.Add(parameterArray[i]);
                }
            }
        }
        public override int Read(byte[] buffer, int offset, int count)
        {
            int num2 = 0;

            byte[] sourceArray = null;
            if (this._cachedBytes == null)
            {
                throw ADP.StreamClosed("Read");
            }
            if (buffer == null)
            {
                throw ADP.ArgumentNull("buffer");
            }
            if ((offset < 0) || (count < 0))
            {
                throw ADP.ArgumentOutOfRange(string.Empty, (offset < 0) ? "offset" : "count");
            }
            if ((buffer.Length - offset) < count)
            {
                throw ADP.ArgumentOutOfRange("count");
            }
            if (this._cachedBytes.Count > this._currentArrayIndex)
            {
                sourceArray = (byte[])this._cachedBytes[this._currentArrayIndex];
                while (count > 0)
                {
                    if (sourceArray.Length <= this._currentPosition)
                    {
                        this._currentArrayIndex++;
                        if (this._cachedBytes.Count <= this._currentArrayIndex)
                        {
                            return(num2);
                        }
                        sourceArray           = (byte[])this._cachedBytes[this._currentArrayIndex];
                        this._currentPosition = 0;
                    }
                    int length = sourceArray.Length - this._currentPosition;
                    if (length > count)
                    {
                        length = count;
                    }
                    Array.Copy(sourceArray, this._currentPosition, buffer, offset, length);
                    this._currentPosition += length;
                    count  -= length;
                    offset += length;
                    num2   += length;
                }
                return(num2);
            }
            return(0);
        }
        static public void DeriveParameters(OleDbCommand command)   // MDAC 65927
        {
            OleDbConnection.ExecutePermission.Demand();

            if (null == command)
            {
                throw ADP.ArgumentNull("command");
            }
            switch (command.CommandType)
            {
            case System.Data.CommandType.Text:
                throw ADP.DeriveParametersNotSupported(command);

            case System.Data.CommandType.StoredProcedure:
                break;

            case System.Data.CommandType.TableDirect:
                // CommandType.TableDirect - do nothing, parameters are not supported
                throw ADP.DeriveParametersNotSupported(command);

            default:
                throw ADP.InvalidCommandType(command.CommandType);
            }
            if (ADP.IsEmpty(command.CommandText))
            {
                throw ADP.CommandTextRequired(ADP.DeriveParameters);
            }
            OleDbConnection connection = command.Connection;

            if (null == connection)
            {
                throw ADP.ConnectionRequired(ADP.DeriveParameters);
            }
            ConnectionState state = connection.State;

            if (ConnectionState.Open != state)
            {
                throw ADP.OpenConnectionRequired(ADP.DeriveParameters, state);
            }
            OleDbParameter[] list = DeriveParametersFromStoredProcedure(connection, command);

            OleDbParameterCollection parameters = command.Parameters;

            parameters.Clear();

            for (int i = 0; i < list.Length; ++i)
            {
                parameters.Add(list[i]);
            }
        }
示例#10
0
        public int GetOrdinal(string fieldName)   // V1.2.3300
        {
            if (null == fieldName)
            {
                throw ADP.ArgumentNull("fieldName");
            }
            int index = IndexOf(fieldName);

            if (-1 == index)
            {
                throw ADP.IndexOutOfRange(fieldName);
            }
            return(index);
        }
        public int GetOrdinal(string fieldName)
        {
            if (fieldName == null)
            {
                throw ADP.ArgumentNull("fieldName");
            }
            int index = this.IndexOf(fieldName);

            if (-1 == index)
            {
                throw ADP.IndexOutOfRange(fieldName);
            }
            return(index);
        }
示例#12
0
        public int GetOrdinal(string fieldName)
        {
            if (fieldName == null)
            {
                throw ADP.ArgumentNull(nameof(fieldName));
            }
            int index = IndexOf(fieldName);

            if (index == -1)
            {
                throw ADP.IndexOutOfRange(fieldName);
            }
            return(index);
        }
        public override int GetValues(object[] values)
        {
            this.EnsureCanGetCol("GetValues", 0);
            if (values == null)
            {
                throw ADP.ArgumentNull("values");
            }
            int num2 = (values.Length < this._visibleColumnCount) ? values.Length : this._visibleColumnCount;

            for (int i = 0; i < num2; i++)
            {
                values[this._indexMap[i]] = this.GetValue(i);
            }
            return(num2);
        }
示例#14
0
        /// <include file='doc\sqlrecord.uex' path='docs/doc[@for="SqlRecord.GetSqlValues"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public int GetSqlValues(object[] values)
        {
            if (null == values)
            {
                throw ADP.ArgumentNull("values");
            }

            int copyLen = (values.Length < _schemaInfo.Length) ? values.Length : _schemaInfo.Length;

            for (int i = 0; i < copyLen; i++)
            {
                values[i] = _sqlValues[i];
            }
            return(copyLen);
        }
示例#15
0
        public virtual int GetValues(object[] values)
        {
            this.EnsureSubclassOverride();
            if (values == null)
            {
                throw ADP.ArgumentNull("values");
            }
            int num2 = (values.Length < this.FieldCount) ? values.Length : this.FieldCount;

            for (int i = 0; i < num2; i++)
            {
                values[i] = this.GetValue(i);
            }
            return(num2);
        }
示例#16
0
        //  SqlDataRecord public API
        /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/ctor/*' />
        public SqlDataRecord(params SqlMetaData[] metaData)
        {
            // Initial consistency check
            if (metaData == null)
            {
                throw ADP.ArgumentNull(nameof(metaData));
            }

            _columnMetaData    = new SqlMetaData[metaData.Length];
            _columnSmiMetaData = new SmiExtendedMetaData[metaData.Length];
#if NETFRAMEWORK
            ulong smiVersion = SmiVersion;
#endif
            for (int i = 0; i < _columnSmiMetaData.Length; i++)
            {
                if (metaData[i] == null)
                {
                    throw ADP.ArgumentNull($"{nameof(metaData)}[{i}]");
                }
                _columnMetaData[i]    = metaData[i];
                _columnSmiMetaData[i] = MetaDataUtilsSmi.SqlMetaDataToSmiExtendedMetaData(_columnMetaData[i]);
#if NETFRAMEWORK
                if (!MetaDataUtilsSmi.IsValidForSmiVersion(_columnSmiMetaData[i], smiVersion))
                {
                    throw ADP.VersionDoesNotSupportDataType(_columnSmiMetaData[i].TypeName);
                }
#endif
            }

            _eventSink = new SmiEventSink_Default();
#if NETFRAMEWORK
            if (InOutOfProcHelper.InProc)
            {
                _recordContext           = SmiContextFactory.Instance.GetCurrentContext();
                _recordBuffer            = _recordContext.CreateRecordBuffer(_columnSmiMetaData, _eventSink);
                _usesStringStorageForXml = false;
            }
            else
            {
                _recordContext           = null;
                _recordBuffer            = new MemoryRecordBuffer(_columnSmiMetaData);
                _usesStringStorageForXml = true;
            }
#else
            _recordBuffer = new MemoryRecordBuffer(_columnSmiMetaData);
            _eventSink.ProcessMessagesAndThrow();
#endif
        }
 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == null)
     {
         throw ADP.ArgumentNull("destinationType");
     }
     if (typeof(InstanceDescriptor) == destinationType)
     {
         OleDbConnectionStringBuilder options = value as OleDbConnectionStringBuilder;
         if (options != null)
         {
             return(this.ConvertToInstanceDescriptor(options));
         }
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
示例#18
0
 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == null)
     {
         throw ADP.ArgumentNull("destinationType");
     }
     if (typeof(System.ComponentModel.Design.Serialization.InstanceDescriptor) == destinationType)
     {
         OleDbConnectionStringBuilder obj = (value as OleDbConnectionStringBuilder);
         if (null != obj)
         {
             return(ConvertToInstanceDescriptor(obj));
         }
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
示例#19
0
 public void CopyToRows(DataRow[] array, int arrayIndex)
 {
     DataRow[] dataRows = _dataRows;
     if (null != dataRows)
     {
         dataRows.CopyTo(array, arrayIndex);
     }
     else
     {
         if (null == array)
         {
             throw ADP.ArgumentNull(nameof(array));
         }
         array[arrayIndex] = Row;
     }
 }
示例#20
0
        /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/GetValues/*' />
        public virtual int GetValues(object[] values)
        {
            if (values == null)
            {
                throw ADP.ArgumentNull(nameof(values));
            }

            int copyLength = (values.Length < FieldCount) ? values.Length : FieldCount;

            for (int i = 0; i < copyLength; i++)
            {
                values[i] = GetValue(i);
            }

            return(copyLength);
        }
示例#21
0
 public int Fill(DataSet dataSet, object ADODBRecordSet, string srcTable)
 {
     if (null == dataSet)
     {
         throw ADP.ArgumentNull("dataSet");
     }
     if (null == ADODBRecordSet)
     {
         throw ADP.ArgumentNull("adodb");
     }
     if (ADP.IsEmpty(srcTable))
     {
         throw ADP.FillRequiresSourceTableName("srcTable");
     }
     return(FillFromADODB((object)dataSet, ADODBRecordSet, srcTable, true));
 }
示例#22
0
 public override void AddRange(System.Array values)
 {
     OnChange();
     if (null == values)
     {
         throw ADP.ArgumentNull(nameof(values));
     }
     foreach (object value in values)
     {
         ValidateType(value);
     }
     foreach (OleDbParameter value in values)
     {
         Validate(-1, value);
         InnerList.Add((OleDbParameter)value);
     }
 }
示例#23
0
        /// <include file='../../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetValues/*' />
        // ISqlUpdateableRecord Implementation
        public virtual int SetValues(params object[] values)
        {
            EnsureSubclassOverride();
            if (values == null)
            {
                throw ADP.ArgumentNull(nameof(values));
            }

            // Allow values array longer than FieldCount, just ignore the extra cells.
            int copyLength = (values.Length > FieldCount) ? FieldCount : values.Length;

            ExtendedClrTypeCode[] typeCodes = new ExtendedClrTypeCode[copyLength];

            // Verify all data values as acceptable before changing current state.
            for (int i = 0; i < copyLength; i++)
            {
                SqlMetaData metaData = GetSqlMetaData(i);
                typeCodes[i] = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType(
                    metaData.SqlDbType,
                    isMultiValued: false,
                    values[i],
                    metaData.Type,
                    SmiVersion
                    );
                if (typeCodes[i] == ExtendedClrTypeCode.Invalid)
                {
                    throw ADP.InvalidCast();
                }
            }

            // Now move the data (it'll only throw if someone plays with the values array between
            //      the validation loop and here, or if an invalid UDT was sent).
            for (int i = 0; i < copyLength; i++)
            {
                if (SmiVersion >= SmiContextFactory.KatmaiVersion)
                {
                    ValueUtilsSmi.SetCompatibleValueV200(_eventSink, _recordBuffer, i, GetSmiMetaData(i), values[i], typeCodes[i], offset: 0, length: 0, peekAhead: null);
                }
                else
                {
                    ValueUtilsSmi.SetCompatibleValue(_eventSink, _recordBuffer, i, GetSmiMetaData(i), values[i], typeCodes[i], offset: 0);
                }
            }

            return(copyLength);
        }
示例#24
0
 public override void AddRange(Array values)
 {
     this.OnChange();
     if (values == null)
     {
         throw ADP.ArgumentNull("values");
     }
     foreach (object obj2 in values)
     {
         this.ValidateType(obj2);
     }
     foreach (OdbcParameter parameter in values)
     {
         this.Validate(-1, parameter);
         this.InnerList.Add(parameter);
     }
 }
示例#25
0
        public virtual int GetValues(object[] values)
        {
            EnsureSubclassOverride();
            if (null == values)
            {
                throw ADP.ArgumentNull(nameof(values));
            }

            int copyLength = (values.Length < FieldCount) ? values.Length : FieldCount;

            for (int i = 0; i < copyLength; i++)
            {
                values[i] = GetValue(i);
            }

            return(copyLength);
        }
示例#26
0
 /// <include file='..\..\..\..\..\..\..\doc\snippets\Microsoft.Data.SqlClient\SqlParameterCollection.xml' path='docs/members[@name="SqlParameterCollection"]/AddRangeValues1/*' />
 override public void AddRange(System.Array values)
 {
     OnChange();  // fire event before value is validated
     if (null == values)
     {
         throw ADP.ArgumentNull("values");
     }
     foreach (object value in values)
     {
         ValidateType(value);
     }
     foreach (SqlParameter value in values)
     {
         Validate(-1, value);
         InnerList.Add((SqlParameter)value);
     }
 }
        internal OdbcConnectionHandle(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle) : base(ODBC32.SQL_HANDLE.DBC, environmentHandle)
        {
            if (connection == null)
            {
                throw ADP.ArgumentNull("connection");
            }
            if (constr == null)
            {
                throw ADP.ArgumentNull("constr");
            }
            int connectionTimeout = connection.ConnectionTimeout;

            ODBC32.RetCode retcode          = this.SetConnectionAttribute2(ODBC32.SQL_ATTR.LOGIN_TIMEOUT, (IntPtr)connectionTimeout, -5);
            string         connectionString = constr.UsersConnectionString(false);

            retcode = this.Connect(connectionString);
            connection.HandleError(this, retcode);
        }
        public void AddCommandDependency(SqlCommand command)
        {
            IntPtr ptr;

            Bid.NotificationsScopeEnter(out ptr, "<sc.SqlDependency.AddCommandDependency|DEP> %d#", this.ObjectID);
            try
            {
                if (command == null)
                {
                    throw ADP.ArgumentNull("command");
                }
                this.AddCommandInternal(command);
            }
            finally
            {
                Bid.ScopeLeave(ref ptr);
            }
        }
示例#29
0
        public SqlFileStream
        (
            string path,
            byte[] transactionContext,
            System.IO.FileAccess access,
            System.IO.FileOptions options,
            Int64 allocationSize
        )
        {
            IntPtr hscp;

            Bid.ScopeEnter(out hscp, "<sc.SqlFileStream.ctor|API> %d# access=%d options=%d path='%ls' ", ObjectID, (int)access, (int)options, path);

            try
            {
                //-----------------------------------------------------------------
                // precondition validation

                if (transactionContext == null)
                {
                    throw ADP.ArgumentNull("transactionContext");
                }

                if (path == null)
                {
                    throw ADP.ArgumentNull("path");
                }

                //-----------------------------------------------------------------

                m_disposed = false;
                m_fs       = null;

                OpenSqlFileStream(path, transactionContext, access, options, allocationSize);

                // only set internal state once the file has actually been successfully opened
                this.Name = path;
                this.TransactionContext = transactionContext;
            }
            finally
            {
                Bid.ScopeLeave(ref hscp);
            }
        }
 public void ExecuteAndSend(SqlCommand command)
 {
     this.SetPipeBusy();
     try
     {
         this.EnsureNormalSendValid("ExecuteAndSend");
         if (command == null)
         {
             throw ADP.ArgumentNull("command");
         }
         SqlConnection connection2 = command.Connection;
         if (connection2 == null)
         {
             using (SqlConnection connection = new SqlConnection("Context Connection=true"))
             {
                 connection.Open();
                 try
                 {
                     command.Connection = connection;
                     command.ExecuteToPipe(this._smiContext);
                 }
                 finally
                 {
                     command.Connection = null;
                 }
                 return;
             }
         }
         if (ConnectionState.Open != connection2.State)
         {
             throw ADP.ClosedConnectionError();
         }
         if (!(connection2.InnerConnection is SqlInternalConnectionSmi))
         {
             throw SQL.SqlPipeCommandHookedUpToNonContextConnection();
         }
         command.ExecuteToPipe(this._smiContext);
     }
     finally
     {
         this.ClearPipeBusy();
     }
 }