예제 #1
0
파일: SNIError.cs 프로젝트: noahfalk/corefx
 public SNIError(SNIProviders provider, uint nativeError, uint sniErrorCode, string errorMessage)
 {
     this.lineNumber = 0;
     this.function = string.Empty;
     this.provider = provider;
     this.nativeError = nativeError;
     this.sniError = sniErrorCode;
     this.errorMessage = errorMessage;
     this.exception = null;
 }
예제 #2
0
파일: SNIError.cs 프로젝트: noahfalk/corefx
 public SNIError(SNIProviders provider, uint sniErrorCode, Exception sniException)
 {
     this.lineNumber = 0;
     this.function = string.Empty;
     this.provider = provider;
     this.nativeError = 0;
     this.sniError = sniErrorCode;
     this.errorMessage = string.Empty;
     this.exception = sniException;
 }
예제 #3
0
        public SNIError(SNIProviders provider, SNIErrorCode sniErrorCode, Exception sniException)
        {
            Debug.Assert(sniException != null);

            this.provider     = provider;
            this.nativeError  = 0;
            this.sniError     = sniErrorCode;
            this.errorMessage = null;
            this.exception    = sniException;
        }
예제 #4
0
 public SNIError(SNIProviders provider, uint sniErrorCode, Exception sniException, uint nativeErrorCode = 0)
 {
     lineNumber    = 0;
     function      = string.Empty;
     this.provider = provider;
     nativeError   = nativeErrorCode;
     sniError      = sniErrorCode;
     errorMessage  = string.Empty;
     exception     = sniException;
 }
예제 #5
0
 public SNIError(SNIProviders provider, uint sniErrorCode, Exception sniException)
 {
     this.lineNumber   = 0;
     this.function     = string.Empty;
     this.provider     = provider;
     this.nativeError  = 0;
     this.sniError     = sniErrorCode;
     this.errorMessage = string.Empty;
     this.exception    = sniException;
 }
예제 #6
0
 public SNIError(SNIProviders provider, uint nativeError, uint sniErrorCode, string errorMessage)
 {
     this.lineNumber   = 0;
     this.function     = string.Empty;
     this.provider     = provider;
     this.nativeError  = nativeError;
     this.sniError     = sniErrorCode;
     this.errorMessage = errorMessage;
     this.exception    = null;
 }
예제 #7
0
        public SNIError(SNIProviders provider, uint nativeError, uint sniErrorCode, string errorMessage)
        {
            this.lineNumber  = 0;
            this.function    = "";
            this.provider    = provider;
            this.nativeError = nativeError;
            this.sniError    = sniErrorCode;

            // Hardcode "TCP Provider" to keep TDS parser happy
            this.errorMessage = "TCP Provider: " + errorMessage + Environment.NewLine;
        }
예제 #8
0
        public SNIError(SNIProviders provider, uint nativeError, uint sniErrorCode, string errorMessage)
        {
            this.lineNumber = 0;
            this.function = "";
            this.provider = provider;
            this.nativeError = nativeError;
            this.sniError = sniErrorCode;

            // Hardcode "TCP Provider" to keep TDS parser happy
            this.errorMessage = "TCP Provider: " + errorMessage + Environment.NewLine;
        }
예제 #9
0
        public SNIError(SNIProviders provider, uint nativeError, SNIErrorCode sniErrorCode, string errorMessage)
        {
            Debug.Assert(errorMessage != null);
            Debug.Assert((errorMessage.Length > 0) || sniErrorCode != 0);

            this.provider     = provider;
            this.nativeError  = nativeError;
            this.sniError     = sniErrorCode;
            this.errorMessage = errorMessage;
            this.exception    = null;
        }
예제 #10
0
        /// <summary>
        /// Write data to a stream asynchronously
        /// </summary>
        /// <param name="stream">Stream to write to</param>
        public void WriteToStreamAsync(Stream stream, SNIAsyncCallback callback, SNIProviders provider, bool disposeAfterWriteAsync = false)
        {
            // Treat local function as a static and pass all params otherwise as async will allocate
            async Task WriteToStreamAsync(SNIPacket packet, SNIAsyncCallback cb, SNIProviders providers, bool disposeAfter, Task task)
            {
                uint status = TdsEnums.SNI_SUCCESS;

                try
                {
                    await task.ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    SNILoadHandle.SingletonInstance.LastError = new SNIError(providers, SNICommon.InternalExceptionError, e);
                    status = TdsEnums.SNI_ERROR;
                }

                cb(packet, status);

                if (disposeAfter)
                {
                    packet.Release();
                }
            }

            Task t = stream.WriteAsync(_data, _headerLength, _dataLength, CancellationToken.None);

            if ((t.Status & TaskStatus.RanToCompletion) != 0)
            {
                // Read the result to register as complete for the Task
                t.GetAwaiter().GetResult();

                callback(this, TdsEnums.SNI_SUCCESS);

                if (disposeAfterWriteAsync)
                {
                    Release();
                }

                // Completed
                return;
            }

            // Not complete or error call the async local function to complete
            _ = WriteToStreamAsync(this, callback, provider, disposeAfterWriteAsync, t);
        }
예제 #11
0
        /// <summary>
        /// Write data to a stream asynchronously
        /// </summary>
        /// <param name="stream">Stream to write to</param>
        /// <param name="callback"></param>
        /// <param name="provider"></param>
        /// <param name="disposeAfterWriteAsync"></param>
        public void WriteToStreamAsync(Stream stream, SNIAsyncCallback callback, SNIProviders provider, bool disposeAfterWriteAsync = false)
        {
            // Treat local function as a static and pass all params otherwise as async will allocate
            async Task WriteToStreamAsync(SNIPacket packet, SNIAsyncCallback cb, SNIProviders providers, bool disposeAfter, ValueTask valueTask)
            {
                uint status = TdsEnums.SNI_SUCCESS;

                try
                {
                    await valueTask.ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    SNILoadHandle.SingletonInstance.LastError = new SNIError(providers, SNICommon.InternalExceptionError, e);
                    status = TdsEnums.SNI_ERROR;
                }

                cb(packet, status);

                if (disposeAfter)
                {
                    packet.Dispose();
                }
            }

            ValueTask vt = stream.WriteAsync(new Memory <byte>(_data, 0, _length), CancellationToken.None);

            if (vt.IsCompletedSuccessfully)
            {
                // Read the result to register as complete for the ValueTask
                vt.GetAwaiter().GetResult();

                callback(this, TdsEnums.SNI_SUCCESS);

                if (disposeAfterWriteAsync)
                {
                    Dispose();
                }

                // Completed
                return;
            }

            // Not complete or error call the async local function to complete
            _ = WriteToStreamAsync(this, callback, provider, disposeAfterWriteAsync, vt);
        }
예제 #12
0
 /// <summary>
 /// Sets last error encountered for SNI
 /// </summary>
 /// <param name="provider">SNI provider</param>
 /// <param name="sniError">SNI error code</param>
 /// <param name="sniException">SNI Exception</param>
 /// <returns></returns>
 internal static uint ReportSNIError(SNIProviders provider, uint sniError, Exception sniException)
 {
     SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.SNICommon. ReportSNIError |SNI|ERR > Provider ={0}, SNI Error ={1}, Exception ={2}", provider, sniError, sniException.Message);
     return(ReportSNIError(new SNIError(provider, sniError, sniException)));
 }
예제 #13
0
 private void ReportSNIError(SNIProviders provider)
 {
     SNILoadHandle.SingletonInstance.LastError = new SNIError(provider, 0, SNICommon.InvalidConnStringError, string.Empty);
     IsBadDataSource = true;
 }
예제 #14
0
 /// <summary>
 /// Sets last error encountered for SNI
 /// </summary>
 /// <param name="provider">SNI provider</param>
 /// <param name="nativeError">Native error code</param>
 /// <param name="sniError">SNI error code</param>
 /// <param name="errorMessage">Error message</param>
 /// <returns></returns>
 internal static uint ReportSNIError(SNIProviders provider, uint nativeError, uint sniError, string errorMessage)
 {
     SNILoadHandle.SingletonInstance.LastError = new SNIError(provider, nativeError, sniError, errorMessage);
     return(TdsEnums.SNI_ERROR);
 }
예제 #15
0
 /// <summary>
 /// Sets last error encountered for SNI
 /// </summary>
 /// <param name="provider">SNI provider</param>
 /// <param name="nativeError">Native error code</param>
 /// <param name="sniError">SNI error code</param>
 /// <param name="errorMessage">Error message</param>
 /// <returns></returns>
 internal static uint ReportSNIError(SNIProviders provider, uint nativeError, uint sniError, string errorMessage)
 {
     SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.SNICommon. ReportSNIError |SNI|ERR > Provider ={0}, native Error ={1}, SNI Error ={2}, Error Message ={3}", provider, nativeError, sniError, errorMessage);
     return(ReportSNIError(new SNIError(provider, nativeError, sniError, errorMessage)));
 }
예제 #16
0
 /// <summary>
 /// Sets last error encountered for SNI
 /// </summary>
 /// <param name="provider">SNI provider</param>
 /// <param name="nativeError">Native error code</param>
 /// <param name="sniError">SNI error code</param>
 /// <param name="errorMessage">Error message</param>
 /// <returns></returns>
 internal static uint ReportSNIError(SNIProviders provider, uint nativeError, uint sniError, string errorMessage)
 {
     SNILoadHandle.SingletonInstance.LastError = new SNIError(provider, nativeError, sniError, errorMessage);
     return TdsEnums.SNI_ERROR;
 }
예제 #17
0
 /// <summary>
 /// Sets last error encountered for SNI
 /// </summary>
 /// <param name="provider">SNI provider</param>
 /// <param name="sniError">SNI error code</param>
 /// <param name="sniException">SNI Exception</param>
 /// <returns></returns>
 internal static uint ReportSNIError(SNIProviders provider, uint sniError, Exception sniException)
 {
     return ReportSNIError(new SNIError(provider, sniError, sniException));
 }
예제 #18
0
 /// <summary>
 /// Sets last error encountered for SNI
 /// </summary>
 /// <param name="provider">SNI provider</param>
 /// <param name="sniError">SNI error code</param>
 /// <param name="sniException">SNI Exception</param>
 /// <returns></returns>
 internal static uint ReportSNIError(SNIProviders provider, uint sniError, Exception sniException)
 {
     return(ReportSNIError(new SNIError(provider, sniError, sniException)));
 }
예제 #19
0
 /// <summary>
 /// Sets last error encountered for SNI
 /// </summary>
 /// <param name="provider">SNI provider</param>
 /// <param name="nativeError">Native error code</param>
 /// <param name="sniError">SNI error code</param>
 /// <param name="errorMessage">Error message</param>
 /// <returns></returns>
 internal static uint ReportSNIError(SNIProviders provider, uint nativeError, uint sniError, string errorMessage)
 {
     return(ReportSNIError(new SNIError(provider, nativeError, sniError, errorMessage)));
 }
예제 #20
0
 /// <summary>
 /// Sets last error encountered for SNI
 /// </summary>
 /// <param name="provider">SNI provider</param>
 /// <param name="sniError">SNI error code</param>
 /// <param name="sniException">SNI Exception</param>
 /// <returns></returns>
 internal static uint ReportSNIError(SNIProviders provider, uint sniError, Exception sniException)
 {
     SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.ERR, "Provider = {0}, SNI Error = {1}, Exception = {2}", args0: provider, args1: sniError, args2: sniException?.Message);
     return(ReportSNIError(new SNIError(provider, sniError, sniException)));
 }
예제 #21
0
 /// <summary>
 /// Sets last error encountered for SNI
 /// </summary>
 /// <param name="provider">SNI provider</param>
 /// <param name="nativeError">Native error code</param>
 /// <param name="sniError">SNI error code</param>
 /// <param name="errorMessage">Error message</param>
 /// <returns></returns>
 internal static uint ReportSNIError(SNIProviders provider, uint nativeError, uint sniError, string errorMessage)
 {
     return ReportSNIError(new SNIError(provider, nativeError, sniError, errorMessage));
 }
예제 #22
0
 /// <summary>
 /// Sets last error encountered for SNI
 /// </summary>
 /// <param name="provider">SNI provider</param>
 /// <param name="nativeError">Native error code</param>
 /// <param name="sniError">SNI error code</param>
 /// <param name="errorMessage">Error message</param>
 /// <returns></returns>
 internal static uint ReportSNIError(SNIProviders provider, uint nativeError, uint sniError, string errorMessage)
 {
     SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Provider = {0}, native Error = {1}, SNI Error = {2}, Error Message = {3}", args0: provider, args1: nativeError, args2: sniError, args3: errorMessage);
     return(ReportSNIError(new SNIError(provider, nativeError, sniError, errorMessage)));
 }
예제 #23
0
        /// <summary>
        /// Write data to a stream asynchronously
        /// </summary>
        /// <param name="stream">Stream to write to</param>
        public async void WriteToStreamAsync(Stream stream, SNIAsyncCallback callback, SNIProviders provider)
        {
            uint status = TdsEnums.SNI_SUCCESS;

            try
            {
                await stream.WriteAsync(_data, 0, _length, CancellationToken.None).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                SNILoadHandle.SingletonInstance.LastError = new SNIError(provider, SNICommon.InternalExceptionError, e);
                status = TdsEnums.SNI_ERROR;
            }
            callback(this, status);
        }
예제 #24
0
 /// <summary>
 /// Sets last error encountered for SNI
 /// </summary>
 /// <param name="provider">SNI provider</param>
 /// <param name="sniError">SNI error code</param>
 /// <param name="sniException">SNI Exception</param>
 /// <param name="nativeErrorCode">Native SNI error code</param>
 /// <returns></returns>
 internal static uint ReportSNIError(SNIProviders provider, uint sniError, Exception sniException, uint nativeErrorCode = 0)
 {
     SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Provider = {0}, SNI Error = {1}, Exception = {2}", args0: provider, args1: sniError, args2: sniException?.Message);
     return(ReportSNIError(new SNIError(provider, sniError, sniException, nativeErrorCode)));
 }