public void ExecuteQueryReportsFailure()
        {
            string errorMsg = "Database connection closed";
            DataException exception = new DataException(errorMsg);
            ExecuteInUI eiu = new ExecuteInUI();
            IList objectGraph = new ArrayList();
            Expect.On(prj).Call(prj.RunHql(query,parameters)).Return(objectGraph);
            Expect.On(prj).Call(prj.RunHqlAsRawSql(query,parameters)).Throw(exception);

            view.ExecuteInUIThread(null);
            LastCall.On(view).Callback(new ExecuteInUI.ExecuteInUIDelegate(eiu.ExecuteInUIThread));
            view.AddException(exception);

            view.EndWait("An exception occured executing query");

            mocks.ReplayAll();
            command.Execute();
        }
Exemplo n.º 2
0
 // ���������� ���������� ADO.NET
 private static void HandleDataException(DataException dataException)
 {
     ShowExceptionDialog(dataException, "��� ������ �����������, ���� ������������ �������� �� ��� ������ ���� �����, ���� ��� ������������ ��� ���� ��������. ��������� ������������ �������� � ��������� ������� ����� ������.", "����������� ���� ������ ��������", MessageBoxIcon.Information, true);
 }
        /// <summary>
        /// If the inner exception chain of the specified <see cref="DataException"/> has
        /// a <see cref="SqlException"/> that inner exception is returned.
        /// </summary>
        /// <param name="dataException">The exception to search through</param>
        /// <returns>The inner <see cref="SqlException"/> or null</returns>
        public static SqlException GetUnderlyingSqlException(DataException dataException)
        {
            if (dataException == null)
            {
                throw new ArgumentNullException("dataException");
            }

            Exception currentException = dataException;
            while (currentException != null)
            {
                SqlException sqlException = currentException as SqlException;
                if (sqlException != null)
                {
                    return sqlException;
                }

                currentException = currentException.InnerException;
            }

            return null;
        }
Exemplo n.º 4
0
Arquivo: Demo.cs Projeto: wli3/Its.Log
        public void Formatting3_Exception_formatting_is_very_descriptive_by_default()
        {
            Log.EntryPosted += (sender, e) => Console.WriteLine(e.LogEntry.ToLogString());

            var dataException = new DataException("oops!");
            dataException.Data["why?"] = "because";
            var outerException = new ReflectionTypeLoadException(new[] { GetType() }, new[] { dataException });

            try
            {
                throw outerException;
            }
            catch (Exception ex)
            {
                Log.Write(() => ex);
            }
        }
Exemplo n.º 5
0
Arquivo: Demo.cs Projeto: wli3/Its.Log
        public void Formatting4_Every_exception_gets_an_unique_id_which_is_shared_among_inner_and_outer_exceptions()
        {
            Log.EntryPosted += (sender, e) => Console.WriteLine(e.LogEntry.ToLogString());

            // scope down the formatting to show just the relevant bits
            Formatter<LogEntry>.RegisterForMembers(e => e.ExceptionId, e => e.EventType, e => e.Subject);
            Formatter<DataException>.RegisterForMembers(e => e.Data, e => e.InnerException);
            Formatter<NullReferenceException>.RegisterForMembers(e => e.Data, e => e.InnerException);
            Formatter<InvalidOperationException>.RegisterForMembers(e => e.Data, e => e.InnerException);
            ;

            var dataException = new DataException("oops!");
            dataException.Data["why?"] = "because";
            var nullReferenceException = new NullReferenceException("oh my.", dataException);
            var outerException = new InvalidOperationException("oh noes!", nullReferenceException);

            try
            {
                throw outerException;
            }
            catch (Exception ex)
            {
                Log.Write(() => ex);
            }
        }
        public void A_insert_concurrency_DataException_is_a_concurrency_exception()
        {
            var exception = new DataException("Cannot insert duplicate key");

            exception.IsConcurrencyException().Should().BeTrue();
        }
 internal static DataException Data(string message)
 {
     DataException e = new DataException(message);
     TraceExceptionAsReturnValue(e);
     return e;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a response that represents a data exception failure.
        /// </summary>
        /// <param name="dispatchId"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private static byte[] Exception(int dispatchId, DataException e)
        {
            int code = /* TODO: e.ErrorCode */ -1;
            string msg = e.Message;
            if (String.IsNullOrEmpty(msg))
                msg = "NULL exception message";

            string server_msg = "";
            string stack_trace = "";

            if (e is DbDataException) {
                DbDataException me = (DbDataException)e;
                server_msg = me.ServerErrorMessage;
                stack_trace = me.ServerErrorStackTrace;
            } else {
                stack_trace = e.StackTrace;
            }

            MemoryStream output = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(output, Encoding.Unicode);
            writer.Write(dispatchId);
            writer.Write(ProtocolConstants.Exception);
            writer.Write(code);
            writer.Write(msg);
            writer.Write(stack_trace);

            return output.ToArray();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Deletes the current Language.
        /// 
        /// Notice: this can have various sideeffects - use with care.
        /// </summary>
        /// <remarks>
        /// You cannot delete the default language: en-US, this is installed by default and is required.
        /// </remarks>
        public void Delete()
        {            
            lock (Locker)
            {
                if (SqlHelper.ExecuteScalar<int>("SELECT count(id) FROM umbracoDomains where domainDefaultLanguage = @id",
                   SqlHelper.CreateParameter("@id", id)) == 0)
                {

                    var e = new DeleteEventArgs();
                    FireBeforeDelete(e);

                    if (!e.Cancel)
                    {
                        //remove the dictionary entries first
                        Item.RemoveByLanguage(id);

                        SqlHelper.ExecuteNonQuery("delete from umbracoLanguage where id = @id",
                            SqlHelper.CreateParameter("@id", id));

                        FireAfterDelete(e);
                    }
                }
                else
                {
                    var e = new DataException("Cannot remove language " + _friendlyName + " because it's attached to a domain on a node");
                    LogHelper.Error<Language>("Cannot remove language " + _friendlyName + " because it's attached to a domain on a node", e);
                    throw e;
                }   
            }            
        }
Exemplo n.º 10
0
 public void AfterThrowing(DataException ex)
 {
     var a = 0;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Deletes the current Language.
        /// 
        /// Notice: this can have various sideeffects - use with care.
        /// </summary>
        /// <remarks>
        /// You cannot delete the default language: en-US, this is installed by default and is required.
        /// </remarks>
        public void Delete()
        {            
            lock (Locker)
            {

                if (ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar<int>("SELECT count(id) FROM umbracoDomains where domainDefaultLanguage = @id", new { id = id }) == 0)
                {
                    var e = new DeleteEventArgs();
                    FireBeforeDelete(e);

                    if (!e.Cancel)
                    {
                        //remove the dictionary entries first
                        Item.RemoveByLanguage(id);

                        ApplicationContext.Current.DatabaseContext.Database.Delete<LanguageDto>("where id = @id",
                                                                                                new {id = id});
                        FireAfterDelete(e);
                    }
                }
                else
                {
                    var e = new DataException("Cannot remove language " + _friendlyName + " because it's attached to a domain on a node");
                    LogHelper.Error<Language>("Cannot remove language " + _friendlyName + " because it's attached to a domain on a node", e);
                    throw e;
                }   
            }            
        }