Esempio n. 1
0
        public static void ShowErrors(SqlCeException e)
        {
            SqlCeErrorCollection errorCollection = e.Errors;

            StringBuilder bld   = new StringBuilder();
            Exception     inner = e.InnerException;

            foreach (SqlCeError err in errorCollection)
            {
                bld.Append("\n Error Code: " + err.HResult.ToString("X",
                                                                    System.Globalization.CultureInfo.CurrentCulture));
                bld.Append("\n Message   : " + err.Message);
                bld.Append("\n Minor Err.: " + err.NativeError);
                bld.Append("\n Source    : " + err.Source);

                foreach (int numPar in err.NumericErrorParameters)
                {
                    if (0 != numPar)
                    {
                        bld.Append("\n Num. Par. : " + numPar);
                    }
                }

                foreach (string errPar in err.ErrorParameters)
                {
                    if (String.Empty != errPar)
                    {
                        bld.Append("\n Err. Par. : " + errPar);
                    }
                }
            }
            MessageBox.Show(bld.ToString());
        }
Esempio n. 2
0
        protected internal static void EnableException(System.Exception ex)
        {
            string errorMessages = string.Empty;

            if (ex is SqlCeException) // ошибка SQL
            {
                SqlCeException errSql = ex as SqlCeException;

                /*				if (errSql.Errors[0].Number == 17)
                 *                  errorMessages = "Нет соединения!";
                 *              else if (errSql.Errors[0].Number == 18456)
                 *                  errorMessages = "Ошибка аутентификации!";
                 *              errorMessages += "\n";
                 * */
                for (int i = 0; i < errSql.Errors.Count; i++)
                {
                    errorMessages +=
                        ":" + errSql.Errors[i].Message;
                }
                errorMessages += "Ошибка SQL!";
            }
            else if (ex is IOException)
            {
                IOException errIO = ex as IOException;

                errorMessages += errIO.Message;
            }
            else
            {
                errorMessages += ex.Message;
            }

            clsDialogBox.ErrorBoxShow(errorMessages);
        }
Esempio n. 3
0
        public static void ShowErrors(SqlCeException e)
        {
            SqlCeErrorCollection errorCollection = e.Errors;

            StringBuilder bld   = new StringBuilder();
            Exception     inner = e.InnerException;

            foreach (SqlCeError err in errorCollection)
            {
                bld.Append("\n Error Code: " + err.HResult.ToString("X"));
                bld.Append("\n Message   : " + err.Message);
                bld.Append("\n Minor Err.: " + err.NativeError);
                bld.Append("\n Source    : " + err.Source);

                foreach (int numPar in err.NumericErrorParameters)
                {
                    if (0 != numPar)
                    {
                        bld.Append("\n Num. Par. : " + numPar);
                    }
                }

                foreach (string errPar in err.ErrorParameters)
                {
                    if (String.Empty != errPar)
                    {
                        bld.Append("\n Err. Par. : " + errPar);
                    }
                }

                Console.WriteLine(bld.ToString());
                bld.Remove(0, bld.Length);
            }
        }
Esempio n. 4
0
 private void HandleSQLException(SqlCeException exSQL)
 {
     foreach (SqlCeError errSQL in exSQL.Errors)
     {
         MessageBox.Show(errSQL.Message + " : " + errSQL.Source);
     }
 }
Esempio n. 5
0
        void grid_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            SqlCeException ex      = e.Exception as SqlCeException;
            string         message = "";
            DataGridView   grid    = sender as DataGridView;
            string         source  = " ở dòng: " + (e.RowIndex + 1).ToString() +
                                     ", trong cột: \"" + grid.Columns[e.ColumnIndex].HeaderText + "\"";

            if (ex != null)
            {
                switch (ex.NativeError)
                {
                case 25026:
                    // Message	"A foreign key value cannot be inserted because a corresponding primary key value does not exist.
                    message = "Thông tin không đúng" + source;
                    break;

                case 25016:
                    // Message	"A duplicate value cannot be inserted into a unique index.
                    message = "Thông tin bị trùng" + source + ". Hãy xem lại!";
                    break;

                default:
                    message = e.Exception.Message;
                    break;
                }
            }
            else
            {
                switch (e.Exception.GetType().Name)
                {
                case "FormatException":
                    message = "Dạng thông tin không đúng. Rất có thể bạn đã nhập một chữ vào" +
                              " ô chỉ có thể nhập một số! Sửa lại" + source;
                    break;

                case "InvalidOperationException":
                    if (e.Exception.Message.Contains("max"))
                    {
                        message = "Độ dài thông tin vượt quá mức cho phép. \r\n" + e.Exception.Message;
                    }
                    break;
                }
            }
            FormTableViewer f = ((FormTableViewer)grid.Parent.Parent.Parent);

            if (f.radioSilent.Checked)
            {
                f.timer1.Enabled = true;
                System.Media.SystemSounds.Asterisk.Play();
                f.errorProvider.BindToDataAndErrors(grid.DataSource, "");
                f.errorProvider.SetError(f, message);
                statusText.Text = message;
            }
            else
            {
                Utility.Miscellaneous.ErrorMessage(message);
            }
        }
Esempio n. 6
0
 private static bool HandleInvalidPassword(SqlCeException e)
 {
     if (e.NativeError == 25028 ||
         e.NativeError == 25140 ||
         e.Message.ToLower().Contains("password"))
     {
         return(false);
     }
     throw e;
 }
Esempio n. 7
0
        private void ParseSqlErrorToResultsBox(SqlCeException sqlException)
        {
            this.Resultspanel.Children.Clear();
            var textBox = new TextBox();

            textBox.Foreground = Brushes.Red;
            textBox.FontFamily = new System.Windows.Media.FontFamily("Consolas");
            textBox.Text       = Helpers.DataConnectionHelper.ShowErrors(sqlException);
            this.Resultspanel.Children.Add(textBox);
        }
Esempio n. 8
0
 public static ProviderException AsProviderException(
     this SqlCeException exception)
 {
     switch (exception.NativeError)
     {
     case 25016: // duplicate index constraint
     case 25030: // duplicate check constraint
         return(new UniqueConstraintViolationException(exception));
     }
     return(new ProviderException(exception));
 }
        private Exception HandleException(SqlCeException ex)
        {
            switch (ex.NativeError)
            {
            case -2: return(new TimeoutException(ex.Message, ex));

            case 2601: return(new UniqueKeyException(ex));

            case 547: return(new ForeignKeyException(ex));

            default: return(ex);
            }
        }
        private void WriteToEventLog(SqlCeException e, string action)
        {
            using (EventLog log = new EventLog())
            {
                log.Source = eventSource;
                log.Log    = eventLog;

                string message = exceptionMessage + "\n\n";
                message += "Action: " + action + "\n\n";
                message += "Exception: " + e.ToString();

                log.WriteEntry(message);
            }
        }
Esempio n. 11
0
        private static SqlCeException _GetCEException(Exception e)
        {
            SqlCeException ceEx = null;

            if (e is SqlCeException)
            {
                ceEx = e as SqlCeException;
            }
            else if (e.InnerException != null && e.InnerException is SqlCeException)
            {
                ceEx = e.InnerException as SqlCeException;
            }

            return(ceEx);
        }
Esempio n. 12
0
        private static void ShowError(SqlCeException aSqlCeException)
        {
            String errorText;
            switch (aSqlCeException.NativeError)
            {
                case 25046:
                    errorText = ExceptionStrings.DatabaseFileIsNotFound;
                    break;
                default:
                    errorText = Convert.ToString(aSqlCeException.NativeError) + "; " + aSqlCeException.Message;
                    break;
            }

            ShowError(errorText);
        }
Esempio n. 13
0
        private static string getSQLCEExceptionText(SqlCeException exception)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("Argument can't be null");
            }

            StringBuilder sb = new StringBuilder();

            foreach (SqlCeError error in exception.Errors)
            {
                sb.AppendLine(error.Message);
            }

            return(sb.ToString());
        }
Esempio n. 14
0
        protected override bool IsTransactionFailure(Exception exception)
        {
            SqlCeException localException = exception as SqlCeException;

            if (localException != null)
            {
                foreach (SqlCeError error in localException.Errors)
                {
                    if (IsTransactionFailure(error.NativeError))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 15
0
        private static void ShowError(SqlCeException aSqlCeException)
        {
            String errorText;

            switch (aSqlCeException.NativeError)
            {
            case 25046:
                errorText = ExceptionStrings.DatabaseFileIsNotFound;
                break;

            default:
                errorText = Convert.ToString(aSqlCeException.NativeError) + "; " + aSqlCeException.Message;
                break;
            }

            ShowError(errorText);
        }
Esempio n. 16
0
        /// <summary>
        /// Format a SqlCeException as a String
        /// </summary>
        /// <param name="e"></param>
        /// <returns>A formatted error string</returns>
        public string ShowErrors(SqlCeException e)
        {
            var errorCollection = e.Errors;

            var bld   = new StringBuilder();
            var inner = e.InnerException;

            if (!string.IsNullOrEmpty(e.HelpLink))
            {
                bld.Append("\nCommand text: ");
                bld.Append(e.HelpLink);
            }

            if (null != inner)
            {
                bld.Append("\nInner Exception: " + inner);
            }
            // Enumerate the errors to a message box.
            foreach (SqlCeError err in errorCollection)
            {
                bld.Append("\n Error Code: 0x" + err.HResult.ToString("X", System.Globalization.CultureInfo.InvariantCulture));
                bld.Append("\n Message   : " + err.Message);
                bld.Append("\n Minor Err.: " + err.NativeError);
                bld.Append("\n Source    : " + err.Source);

                // Enumerate each numeric parameter for the error.
                foreach (var numPar in err.NumericErrorParameters)
                {
                    if (0 != numPar)
                    {
                        bld.Append("\n Num. Par. : " + numPar);
                    }
                }

                // Enumerate each string parameter for the error.
                foreach (var errPar in err.ErrorParameters)
                {
                    if (!string.IsNullOrEmpty(errPar))
                    {
                        bld.Append("\n Err. Par. : " + errPar);
                    }
                }
            }
            return(bld.ToString());
        }
Esempio n. 17
0
        private ErrorSeverity GetExceptionSeverity(Exception exception)
        {
            // If the error code indicates an integrity constraint violation or other user-correctable message, severity is user, otherwise, severity is application
            SqlCeException localException = exception as SqlCeException;

            if (localException != null)
            {
                foreach (SqlCeError error in localException.Errors)
                {
                    if (!IsUserCorrectableError(error.NativeError))
                    {
                        return(ErrorSeverity.Application);
                    }
                }
                return(ErrorSeverity.User);
            }
            return(ErrorSeverity.Application);
        }
Esempio n. 18
0
        static public tgConcurrencyException CheckForConcurrencyException(SqlCeException ex)
        {
            tgConcurrencyException ce = null;

            if (ex.Errors != null)
            {
                foreach (SqlCeError err in ex.Errors)
                {
                    if (err.NativeError == 532)
                    {
                        ce = new tgConcurrencyException(err.Message, ex);
                        break;
                    }
                }
            }

            return(ce);
        }
Esempio n. 19
0
        public override System.Exception GetMappedException(Exception ex)
        {
            SqlCeException sqlceException = ex as SqlCeException;

            if (sqlceException == null)
            {
                return(base.GetMappedException(ex));
            }

            if (sqlceException.Errors == null || sqlceException.Errors.Count == 0)
            {
                return(base.GetMappedException(ex));
            }

            SqlCeError            firstError       = sqlceException.Errors[0];
            SqlCeMessage          message          = new SqlCeMessage(firstError);
            SqlCeWrappedException wrappedException = new SqlCeWrappedException(message, ex);

            return(wrappedException);
        }
Esempio n. 20
0
        internal static void ShowErrors(SqlCeException e)
        {
            SqlCeErrorCollection errorCollection = e.Errors;

            StringBuilder bld   = new StringBuilder();
            Exception     inner = e.InnerException;

            if (null != inner)
            {
                Console.Error.WriteLine("Inner Exception: " + inner.ToString());
            }
            // Enumerate the errors to a message box.
            foreach (System.Data.SqlServerCe.SqlCeError err in errorCollection)
            {
                bld.Append("\n Error Code: " + err.HResult.ToString("X", System.Globalization.CultureInfo.InvariantCulture));
                bld.Append("\n Message   : " + err.Message);
                bld.Append("\n Minor Err.: " + err.NativeError);
                bld.Append("\n Source    : " + err.Source);

                // Enumerate each numeric parameter for the error.
                foreach (int numPar in err.NumericErrorParameters)
                {
                    if (0 != numPar)
                    {
                        bld.Append("\n Num. Par. : " + numPar);
                    }
                }

                // Enumerate each string parameter for the error.
                foreach (string errPar in err.ErrorParameters)
                {
                    if (!string.IsNullOrEmpty(errPar))
                    {
                        bld.Append("\n Err. Par. : " + errPar);
                    }
                }

                Console.Error.WriteLine(bld.ToString());
                bld.Remove(0, bld.Length);
            }
        }
Esempio n. 21
0
        public static void ShowErrors(SqlCeException e)
        {
            SqlCeErrorCollection errors  = e.Errors;
            Exception            inner   = e.InnerException;
            StringBuilder        builder = new StringBuilder();

            if (inner != null)
            {
                MessageBox.Show(inner.ToString(), "Inner Exception");
            }

            foreach (SqlCeError error in errors)
            {
                builder.Append("\r Error Code: " + error.HResult.ToString("X"));
                builder.Append("\r Message   : " + error.Message);
                builder.Append("\r Minor Err.: " + error.NativeError);
                builder.Append("\r Source    : " + error.Source);

                foreach (int param in error.NumericErrorParameters)
                {
                    if (param != 0)
                    {
                        builder.Append("\r Num. Par. : " + param.ToString());
                    }
                }

                foreach (string errPar in error.ErrorParameters)
                {
                    if (errPar != String.Empty)
                    {
                        builder.Append("\r Err. Par. : " + errPar);
                    }
                }

                if (builder.ToString().Length > 0)
                {
                    MessageBox.Show(builder.ToString(), "SqlCE Error");
                }
                builder.Remove(0, builder.Length);
            }
        }
Esempio n. 22
0
        public string ComposeSqlErrorMessage(SqlCeException e)
        {
            SqlCeErrorCollection errorCollection = e.Errors;
            StringBuilder bld = new StringBuilder();

            Exception inner = e.InnerException;
            if ((inner != null))
            {
                bld.Append(("Inner Exception: " + inner.ToString()));
            }

            //SqlCeError err;
            foreach (SqlCeError err in errorCollection)
            {
                bld.Append("\r\n" + "Error:" + err.HResult.ToString("X"));
                bld.Append("\r\n" + err.Message);
                bld.Append("\r\n" + "Native Error:" + err.NativeError);
                bld.Append("\r\n" + err.Source);

                //int numPar;
                foreach (int numPar in err.NumericErrorParameters)
                {
                    if (numPar != 0)
                    {
                        bld.Append("\r\n" + "N-Parm:" + numPar.ToString());
                    }
                }

                //string errPar;
                foreach (string errPar in err.ErrorParameters)
                {
                    if (errPar != String.Empty)
                    {
                        bld.Append("\r\n" + "E-Parm:" + errPar);
                    }
                }
            }
            return bld.ToString();
        }
Esempio n. 23
0
        public void ShowErrors(SqlCeException e)
        {
            SqlCeErrorCollection errorCollection = e.Errors;
            StringBuilder        bld             = new StringBuilder();
            Exception            inner           = e.InnerException;

            if (inner != null)
            {
                MessageBox.Show(("Inner Exception: " + inner.ToString()));
            }

            foreach (SqlCeError err  in errorCollection)
            {
                bld.Append("\n" + " Error Code: " + err.HResult.ToString());
                bld.Append("\n" + " Message   : " + err.Message);
                bld.Append("\n" + " Minor Err.: " + err.NativeError);
                bld.Append("\n" + " Source    : " + err.Source);

                foreach (int numPar in err.NumericErrorParameters)
                {
                    if (0 != numPar)
                    {
                        bld.Append("\n" + " Num. Par. : " + numPar);
                    }
                }

                foreach (string errPar in err.ErrorParameters)
                {
                    if (string.Empty != errPar)
                    {
                        bld.Append("\n" + " Err. Par. : " + errPar);
                    }
                }

                MessageBox.Show(bld.ToString());
                bld.Remove(0, bld.Length);
            }
        }
Esempio n. 24
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Opens SQL Server CE database using specified file path.
        /// Upgrades database if scheme version less than the current one.
        /// </summary>
        /// <param name="path">
        /// Database file path.
        /// </param>
        /// <returns>
        /// DataObjectContext object.
        /// </returns>
        public static DataObjectContext OpenDatabase(string path)
        {
            Debug.Assert(path != null);

            try
            {
                string sqlConnStr = DatabaseHelper.BuildSqlConnString(path, true);

                // upgrade database if necessary
                CheckForDbUpgrade(sqlConnStr);

                // create object context
                DataObjectContext ctx = new DataObjectContext(
                    _BuildEntityConnStr(sqlConnStr));

                // keep connection alive to ensure exclusive mode
                ctx.Connection.Open();

                return(ctx);
            }
            catch (Exception e)
            {
                Logger.Error(e);

                SqlCeException ceEx = _GetCEException(e);
                if (ceEx != null &&
                    ceEx.NativeError == SSCE_M_FILESHAREVIOLATION)
                {
                    throw new DataException(Properties.Messages.Error_DbFileSharingViolation,
                                            DataError.FileSharingViolation);
                }
                else
                {
                    throw;
                }
            }
        }
        public void AsynEndSyncThrowsExceptionWhenNoSuchPublication()
        {
            SubscriptionParameters subParams = CreateSubscriptionParams("NoSuchPublication", "Test");
            SqlSubscriptionManager subMgr    = CreateSubscriptionManager();

            subMgr.Add(subParams);

            Subscription sub = subMgr.Subscriptions["Test"];

            subMgr.BeginSynchronize(sub);
            sub.AsyncResult.AsyncWaitHandle.WaitOne(asyncTimeout, false);

            SqlCeException endException = null;

            try
            {
                subMgr.EndSynchronize(sub);
            }
            catch (SqlCeException ex)
            {
                endException = ex;
            }
            Assert.IsNotNull(endException, "Did not raise excepected exception");
        }
Esempio n. 26
0
        public static tgConcurrencyException CheckForConcurrencyException(SqlCeException ex)
        {
            tgConcurrencyException ce = null;

            if (ex.Errors != null)
            {
                foreach (SqlCeError err in ex.Errors)
                {
                    if (err.NativeError == 532)
                    {
                        ce = new tgConcurrencyException(err.Message, ex);
                        break;
                    }
                }
            }

            return ce;
        }
Esempio n. 27
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="message"></param>
 /// <param name="innerException"></param>
 public PublicationMayHaveExpiredException(string message,
                                           SqlCeException innerException) : base(message, innerException)
 {
 }
Esempio n. 28
0
        internal unsafe void Open(bool silent)
        {
            int         num                 = 0;
            int         lcidLocale          = -1;
            int         cbBufferPool        = -1;
            int         dwAutoShrinkPercent = -1;
            int         cMaxPages           = -1;
            int         cMaxTmpPages        = -1;
            int         dwDefaultEscalation = -1;
            int         dwDefaultTimeout    = -1;
            int         dwFlushInterval     = -1;
            object      obj                 = null;
            string      text                = null;
            string      source              = null;
            string      text2               = null;
            string      value               = null;
            SEOPENFLAGS dwFlags             = SEOPENFLAGS.MODE_READ | SEOPENFLAGS.MODE_WRITE;
            bool        flag                = false;
            int         num2                = 0;

            if (isDisposed)
            {
                throw new ObjectDisposedException("SqlCeConnection");
            }
            DateTime utcNow = DateTime.UtcNow;

            if (ConnectionString == null || ConnectionString.Length == 0)
            {
                throw new InvalidOperationException(Res.GetString("ADP_NoConnectionString"));
            }
            if (dataSource == null || dataSource.Trim().Length == 0)
            {
                throw new ArgumentException(Res.GetString("ADP_EmptyDatabaseName"));
            }
            if (isOpened)
            {
                throw new InvalidOperationException(Res.GetString("ADP_ConnectionAlreadyOpen", ConnectionState.Open.ToString()));
            }
            MEOPENINFO mEOPENINFO = default(MEOPENINFO);
            IntPtr     intPtr     = Marshal.AllocCoTaskMem(sizeof(MEOPENINFO));

            if (IntPtr.Zero == intPtr)
            {
                throw new OutOfMemoryException();
            }
            try {
                if (ADP.IsEmpty(modifiedConnStr))
                {
                    throw new InvalidOperationException(Res.GetString("ADP_NoConnectionString"));
                }
                text = ConStringUtil.ReplaceDataDirectory(dataSource);
                obj  = connTokens["Locale Identifier"];
                if (obj != null)
                {
                    lcidLocale = (int)obj;
                }
                obj = connTokens["Max Buffer Size"];
                if (obj != null)
                {
                    cbBufferPool = (int)obj * 1024;
                }
                obj = connTokens["Autoshrink Threshold"];
                if (obj != null)
                {
                    dwAutoShrinkPercent = (int)obj;
                }
                obj = connTokens["Max Database Size"];
                if (obj != null)
                {
                    cMaxPages = (int)obj * 256;
                }
                obj = connTokens["Temp File Max Size"];
                if (obj != null)
                {
                    cMaxTmpPages = (int)obj * 256;
                }
                obj = connTokens["Flush Interval"];
                if (obj != null)
                {
                    dwFlushInterval = (int)obj;
                }
                obj = connTokens["Default Lock Escalation"];
                if (obj != null)
                {
                    dwDefaultEscalation = (int)obj;
                }
                obj = connTokens["Default Lock Timeout"];
                if (obj != null)
                {
                    dwDefaultTimeout = (int)obj;
                }
                obj = connTokens["Temp File Directory"];
                if (obj != null)
                {
                    text2 = (string)obj;
                }
                obj = connTokens["Encryption Mode"];
                if (obj != null)
                {
                    value = (string)obj;
                }
                obj = connTokens["Password"];
                if (obj != null)
                {
                    string text3 = (string)obj;
                    if (text3.Length > 0)
                    {
                        source = text3;
                    }
                }
                obj = connTokens["Case Sensitive"];
                if (obj != null)
                {
                    flag = (bool)obj;
                }
                string text4 = null;
                obj = connTokens["Mode"];
                if (obj != null)
                {
                    text4 = (string)obj;
                }
                num2 = connTokens.FileAccessRetryTimeout * 1000;
                if (text4 != null)
                {
                    switch (text4)
                    {
                    case "Read Only":
                        dwFlags = SEOPENFLAGS.MODE_READ;
                        break;

                    case "Read Write":
                        dwFlags = (SEOPENFLAGS.MODE_READ | SEOPENFLAGS.MODE_WRITE);
                        break;

                    case "Exclusive":
                        dwFlags = (SEOPENFLAGS.MODE_READ | SEOPENFLAGS.MODE_WRITE | SEOPENFLAGS.MODE_SHARE_DENY_READ | SEOPENFLAGS.MODE_SHARE_DENY_WRITE);
                        break;

                    case "Shared Read":
                        dwFlags = (SEOPENFLAGS.MODE_READ | SEOPENFLAGS.MODE_WRITE | SEOPENFLAGS.MODE_SHARE_DENY_WRITE);
                        break;
                    }
                }
                FileIOPermissionAccess fileIOPermissionAccess = FileIOPermissionAccess.Read;
                if (!string.IsNullOrEmpty(text4) && !text4.Equals("Read Only", StringComparison.OrdinalIgnoreCase))
                {
                    fileIOPermissionAccess = (fileIOPermissionAccess | FileIOPermissionAccess.Write | FileIOPermissionAccess.Append);
                }
                SqlCeUtil.DemandForPermission(text, fileIOPermissionAccess);
                if (!string.IsNullOrEmpty(text2))
                {
                    SqlCeUtil.DemandForPermission(text2, FileIOPermissionAccess.AllAccess);
                }
                mEOPENINFO.pwszFileName        = NativeMethods.MarshalStringToLPWSTR(text);
                mEOPENINFO.pwszPassword        = NativeMethods.MarshalStringToLPWSTR(source);
                mEOPENINFO.pwszTempPath        = NativeMethods.MarshalStringToLPWSTR(text2);
                mEOPENINFO.lcidLocale          = lcidLocale;
                mEOPENINFO.cbBufferPool        = cbBufferPool;
                mEOPENINFO.dwAutoShrinkPercent = dwAutoShrinkPercent;
                mEOPENINFO.dwFlushInterval     = dwFlushInterval;
                mEOPENINFO.cMaxPages           = cMaxPages;
                mEOPENINFO.cMaxTmpPages        = cMaxTmpPages;
                mEOPENINFO.dwDefaultTimeout    = dwDefaultTimeout;
                mEOPENINFO.dwDefaultEscalation = dwDefaultEscalation;
                mEOPENINFO.dwFlags             = dwFlags;
                mEOPENINFO.dwEncryptionMode    = ConStringUtil.MapEncryptionMode(value);
                mEOPENINFO.dwLocaleFlags       = 0;
                if (flag)
                {
                    mEOPENINFO.dwLocaleFlags &= 1;
                }
                flushFailureEventHandler = OnFlushFailure;
                Marshal.StructureToPtr((object)mEOPENINFO, intPtr, false);
                num = NativeMethods.OpenStore(intPtr, Marshal.GetFunctionPointerForDelegate((Delegate)flushFailureEventHandler), ref pStoreService, ref pStoreServer, ref pQpServices, ref pSeStore, ref pTx, ref pQpDatabase, ref pQpSession, ref pStoreEvents, ref pError);
                SqlCeException ex = ProcessResults(num, pError, this);
                if (ex != null)
                {
                    if (ex.NativeError != 25035 || num2 == 0)
                    {
                        throw ex;
                    }
                    int      num3     = 100;
                    int      num4     = 1;
                    DateTime utcNow2  = DateTime.UtcNow;
                    TimeSpan timeSpan = utcNow2 - utcNow;
                    while (ex != null && ex.NativeError == 25035 && utcNow <= utcNow2 && timeSpan.TotalMilliseconds < num2 && num4 <= 10)
                    {
                        int num5 = num2 - (int)timeSpan.TotalMilliseconds;
                        if (num5 < num3)
                        {
                            num3 = num5;
                        }
                        Thread.Sleep(num3);
                        num3 *= 2;
                        num   = NativeMethods.OpenStore(intPtr, Marshal.GetFunctionPointerForDelegate((Delegate)flushFailureEventHandler), ref pStoreService, ref pStoreServer, ref pQpServices, ref pSeStore, ref pTx, ref pQpDatabase, ref pQpSession, ref pStoreEvents, ref pError);
                        ex    = ProcessResults(num, pError, this);
                        num4++;
                        utcNow2  = DateTime.UtcNow;
                        timeSpan = utcNow2 - utcNow;
                    }
                    if (ex != null)
                    {
                        throw ex;
                    }
                }
                removePwd = true;
                state     = ConnectionState.Open;
                isOpened  = true;
            } finally {
                Marshal.FreeCoTaskMem(mEOPENINFO.pwszFileName);
                Marshal.FreeCoTaskMem(mEOPENINFO.pwszPassword);
                Marshal.FreeCoTaskMem(mEOPENINFO.pwszTempPath);
                Marshal.FreeCoTaskMem(intPtr);
                if (ConnectionState.Open != state)
                {
                    Close();
                    removePwd = false;
                    state     = ConnectionState.Closed;
                }
            }
            if (!silent)
            {
                OnStateChange(ConnectionState.Closed, ConnectionState.Open);
            }
        }
Esempio n. 29
0
 private Exception HandleException(SqlCeException ex)
 {
     switch (ex.NativeError)
     {
         case -2: return new TimeoutException(ex.Message, ex);
         case 2601: return new UniqueKeyException(ex);
         case 547: return new ForeignKeyException(ex);
         default: return ex;
     }
 }
Esempio n. 30
0
 private string FormatSqlCeException(SqlCeException ex, string sql)
 {
     return(Helper.ShowErrors(ex) + Environment.NewLine + sql);
 }
 private void ParseSqlErrorToResultsBox(SqlCeException sqlException)
 {
     this.Resultspanel.Children.Clear();
     var textBox = new TextBox();
     textBox.Foreground = Brushes.Red;
     textBox.FontFamily = new System.Windows.Media.FontFamily("Consolas");
     textBox.Text = Helpers.DataConnectionHelper.ShowErrors(sqlException);
     this.Resultspanel.Children.Add(textBox);
 }
        private void WriteToEventLog(SqlCeException e, string action)
        {
            using (EventLog log = new EventLog())
            {
                log.Source = eventSource;
                log.Log = eventLog;

                string message = exceptionMessage + "\n\n";
                message += "Action: " + action + "\n\n";
                message += "Exception: " + e.ToString();

                log.WriteEntry(message);
            }
        }