Beispiel #1
0
        // Set the current length of the data
        // If the SqlBytes is Null, setLength will make it non-Null.
        public void SetLength(long value)
        {
            if (value < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(value));
            }

            if (FStream())
            {
                m_stream.SetLength(value);
            }
            else
            {
                // If there is a buffer, even the value of SqlBytes is Null,
                // still allow setting length to zero, which will make it not Null.
                // If the buffer is null, raise exception
                //
                if (null == m_rgbBuf)
                {
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_NoBufferMessage));
                }

                if (value > (long)m_rgbBuf.Length)
                {
                    throw new ArgumentOutOfRangeException(nameof(value));
                }

                else if (IsNull)
                {
                    // At this point we know that value is small enough
                    // Go back in buffer mode
                    _state = SqlBytesCharsState.Buffer;
                }

                _lCurLen = value;
            }

            AssertValid();
        }
Beispiel #2
0
        private const int const_ErrorMessageBufferSize          = 1024; // Buffer size for Local DB error message 1K will be enough for all messages


        internal static string GetLocalDBMessage(int hrCode)
        {
            Debug.Assert(hrCode < 0, "HRCode does not indicate error");
            try
            {
                StringBuilder buffer = new StringBuilder((int)const_ErrorMessageBufferSize);
                UInt32        len    = (UInt32)buffer.Capacity;


                // First try for current culture
                int hResult = LocalDBFormatMessage(hrLocalDB: hrCode, dwFlags: const_LOCALDB_TRUNCATE_ERR_MESSAGE, dwLanguageId: (uint)LocaleInterop.GetCurrentCultureLcid(),
                                                   buffer: buffer, buflen: ref len);
                if (hResult >= 0)
                {
                    return(buffer.ToString());
                }
                else
                {
                    // Message is not available for current culture, try default
                    buffer  = new StringBuilder((int)const_ErrorMessageBufferSize);
                    len     = (UInt32)buffer.Capacity;
                    hResult = LocalDBFormatMessage(hrLocalDB: hrCode, dwFlags: const_LOCALDB_TRUNCATE_ERR_MESSAGE, dwLanguageId: 0 /* thread locale with fallback to English */,
                                                   buffer: buffer, buflen: ref len);
                    if (hResult >= 0)
                    {
                        return(buffer.ToString());
                    }
                    else
                    {
                        return(string.Format(CultureInfo.CurrentCulture, "{0} (0x{1:X}).", Res.GetString("LocalDB_UnobtainableMessage"), hResult));
                    }
                }
            }
            catch (SqlException exc)
            {
                return(string.Format(CultureInfo.CurrentCulture, "{0} ({1}).", Res.GetString("LocalDB_UnobtainableMessage"), exc.Message));
            }
        }
        public static string GetString(string name, params object[] args)
        {
            System.SR loader = GetLoader();
            if (loader == null)
            {
                return(null);
            }
            string format = loader.resources.GetString(name, Culture);

            if ((args == null) || (args.Length <= 0))
            {
                return(format);
            }
            for (int i = 0; i < args.Length; i++)
            {
                string str2 = args[i] as string;
                if ((str2 != null) && (str2.Length > 0x400))
                {
                    args[i] = str2.Substring(0, 0x3fd) + "...";
                }
            }
            return(string.Format(CultureInfo.CurrentCulture, format, args));
        }
Beispiel #4
0
        static private string ConnectionStateMsg(ConnectionState state)
        {
            switch (state)
            {
            case (ConnectionState.Closed):
            case (ConnectionState.Connecting | ConnectionState.Broken):
                return(Res.GetString(Res.ADP_ConnectionStateMsg_Closed));

            case (ConnectionState.Connecting):
                return(Res.GetString(Res.ADP_ConnectionStateMsg_Connecting));

            case (ConnectionState.Open):
                return(Res.GetString(Res.ADP_ConnectionStateMsg_Open));

            case (ConnectionState.Open | ConnectionState.Executing):
                return(Res.GetString(Res.ADP_ConnectionStateMsg_OpenExecuting));

            case (ConnectionState.Open | ConnectionState.Fetching):
                return(Res.GetString(Res.ADP_ConnectionStateMsg_OpenFetching));

            default:
                return(Res.GetString(Res.ADP_ConnectionStateMsg, state.ToString()));
            }
        }
Beispiel #5
0
 public SqlTypeException() : this(Res.GetString(Res.SqlMisc_SqlTypeMessage), null)
 {
 }
Beispiel #6
0
 static internal Exception TransactionZombied(DbTransaction obj)
 {
     return(InvalidOperation(Res.GetString(Res.ADP_TransactionZombied, obj.GetType().Name)));
 }
Beispiel #7
0
 static internal ArgumentException VersionDoesNotSupportDataType(string typeName)
 {
     return(Argument(Res.GetString(Res.ADP_VersionDoesNotSupportDataType, typeName)));
 }
Beispiel #8
0
 static internal ArgumentException ParameterValueOutOfRange(Decimal value)
 {
     return(ADP.Argument(Res.GetString(Res.ADP_ParameterValueOutOfRange, value.ToString((IFormatProvider)null))));
 }
Beispiel #9
0
 static internal ArgumentException DbTypeNotSupported(System.Data.DbType type, Type enumtype)
 {
     return(Argument(Res.GetString(Res.ADP_DbTypeNotSupported, type.ToString(), enumtype.Name)));
 }
Beispiel #10
0
 static internal ArgumentException InvalidDataType(string typeName)
 {
     return(Argument(Res.GetString(Res.ADP_InvalidDataType, typeName)));
 }
Beispiel #11
0
 static internal Exception EmptyDatabaseName()
 {
     return(Argument(Res.GetString(Res.ADP_EmptyDatabaseName)));
 }
Beispiel #12
0
 static internal Exception OpenConnectionPropertySet(string property, ConnectionState state)
 {
     return(InvalidOperation(Res.GetString(Res.ADP_OpenConnectionPropertySet, property, ADP.ConnectionStateMsg(state))));
 }
Beispiel #13
0
 static internal Exception ConnectionAlreadyOpen(ConnectionState state)
 {
     return(InvalidOperation(Res.GetString(Res.ADP_ConnectionAlreadyOpen, ADP.ConnectionStateMsg(state))));
 }
Beispiel #14
0
 static internal Exception ClosedConnectionError()
 {
     return(InvalidOperation(Res.GetString(Res.ADP_ClosedConnectionError)));
 }
Beispiel #15
0
 //
 // : ConnectionUtil
 //
 static internal Exception ConnectionIsDisabled(Exception InnerException)
 {
     return(InvalidOperation(Res.GetString(Res.ADP_ConnectionIsDisabled), InnerException));
 }
Beispiel #16
0
 static internal IOException ErrorReadingFromStream(Exception internalException)
 {
     return(IO(Res.GetString(Res.SqlMisc_StreamErrorMessage), internalException));
 }
Beispiel #17
0
 static internal Exception InternalConnectionError(ConnectionError internalError)
 {
     return(InvalidOperation(Res.GetString(Res.ADP_InternalConnectionError, (int)internalError)));
 }
Beispiel #18
0
 static internal ArgumentException UnknownDataType(Type dataType)
 {
     return(Argument(Res.GetString(Res.ADP_UnknownDataType, dataType.FullName)));
 }
Beispiel #19
0
 static internal Exception InternalError(InternalErrorCode internalError)
 {
     return(InvalidOperation(Res.GetString(Res.ADP_InternalProviderError, (int)internalError)));
 }
Beispiel #20
0
 static internal ArgumentException InvalidSizeValue(int value)
 {
     return(Argument(Res.GetString(Res.ADP_InvalidSizeValue, value.ToString(CultureInfo.InvariantCulture))));
 }
Beispiel #21
0
 static internal Exception InvalidConnectRetryIntervalValue()
 {
     return(Argument(Res.GetString(Res.SQLCR_InvalidConnectRetryIntervalValue)));
 }
Beispiel #22
0
 static internal ArgumentException ParameterValueOutOfRange(SqlDecimal value)
 {
     return(ADP.Argument(Res.GetString(Res.ADP_ParameterValueOutOfRange, value.ToString())));
 }
Beispiel #23
0
 static internal ArgumentOutOfRangeException InvalidDestinationBufferIndex(int maxLen, int dstOffset, string parameterName)
 {
     return(ArgumentOutOfRange(Res.GetString(Res.ADP_InvalidDestinationBufferIndex, maxLen.ToString(CultureInfo.InvariantCulture), dstOffset.ToString(CultureInfo.InvariantCulture)), parameterName));
 }
Beispiel #24
0
 //
 // : IDbTransaction
 //
 static internal Exception ParallelTransactionsNotSupported(DbConnection obj)
 {
     return(InvalidOperation(Res.GetString(Res.ADP_ParallelTransactionsNotSupported, obj.GetType().Name)));
 }
Beispiel #25
0
 static internal IndexOutOfRangeException InvalidBufferSizeOrIndex(int numBytes, int bufferIndex)
 {
     return(IndexOutOfRange(Res.GetString(Res.SQL_InvalidBufferSizeOrIndex, numBytes.ToString(CultureInfo.InvariantCulture), bufferIndex.ToString(CultureInfo.InvariantCulture))));
 }
Beispiel #26
0
 static internal Exception InvalidDataLength(long length)
 {
     return(IndexOutOfRange(Res.GetString(Res.SQL_InvalidDataLength, length.ToString(CultureInfo.InvariantCulture))));
 }
Beispiel #27
0
 static internal InvalidOperationException AsyncOperationPending()
 {
     return(InvalidOperation(Res.GetString(Res.ADP_PendingAsyncOperation)));
 }
Beispiel #28
0
        // Write data of specified length into the SqlChars from specified offset

        public void Write(long offset, char[] buffer, int offsetInBuffer, int count)
        {
            if (FStream())
            {
                if (m_stream.Position != offset)
                {
                    m_stream.Seek(offset, SeekOrigin.Begin);
                }
                m_stream.Write(buffer, offsetInBuffer, count);
            }
            else
            {
                // Validate the arguments
                if (buffer == null)
                {
                    throw new ArgumentNullException("buffer");
                }

                if (m_rgchBuf == null)
                {
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_NoBufferMessage));
                }

                if (offset < 0)
                {
                    throw new ArgumentOutOfRangeException("offset");
                }
                if (offset > m_rgchBuf.Length)
                {
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_BufferInsufficientMessage));
                }

                if (offsetInBuffer < 0 || offsetInBuffer > buffer.Length)
                {
                    throw new ArgumentOutOfRangeException("offsetInBuffer");
                }

                if (count < 0 || count > buffer.Length - offsetInBuffer)
                {
                    throw new ArgumentOutOfRangeException("count");
                }

                if (count > m_rgchBuf.Length - offset)
                {
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_BufferInsufficientMessage));
                }

                if (IsNull)
                {
                    // If NULL and there is buffer inside, we only allow writing from
                    // offset zero.
                    //
                    if (offset != 0)
                    {
                        throw new SqlTypeException(Res.GetString(Res.SqlMisc_WriteNonZeroOffsetOnNullMessage));
                    }

                    // treat as if our current length is zero.
                    // Note this has to be done after all inputs are validated, so that
                    // we won't throw exception after this point.
                    //
                    _lCurLen = 0;
                    _state   = SqlBytesCharsState.Buffer;
                }
                else if (offset > _lCurLen)
                {
                    // Don't allow writing from an offset that this larger than current length.
                    // It would leave uninitialized data in the buffer.
                    //
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_WriteOffsetLargerThanLenMessage));
                }

                if (count != 0)
                {
                    // ProjectK\Core doesn't support long-typed array indexers
                    Debug.Assert(offset < int.MaxValue);
                    Array.Copy(buffer, offsetInBuffer, m_rgchBuf, checked ((int)offset), count);

                    // If the last position that has been written is after
                    // the current data length, reset the length
                    if (_lCurLen < offset + count)
                    {
                        _lCurLen = offset + count;
                    }
                }
            }

            AssertValid();
        }
Beispiel #29
0
 //
 // : Stream
 //
 static internal Exception StreamClosed([CallerMemberName] string method = "")
 {
     return(InvalidOperation(Res.GetString(Res.ADP_StreamClosed, method)));
 }
Beispiel #30
0
 static public Exception InvalidOffsetLength()
 {
     return(_Argument(Res.GetString(Res.Data_InvalidOffsetLength)));
 }
 private static System.SR GetLoader()
 {
     if (loader == null)
     {
         System.SR sr = new System.SR();
         Interlocked.CompareExchange<System.SR>(ref loader, sr, null);
     }
     return loader;
 }