コード例 #1
0
        public static void WriteLog(Exception ex)
        {
            // Se guarda la información del error en el archivo
            System.IO.StreamWriter    stream = new System.IO.StreamWriter("\\ErroresIntegracion.TXT", true);
            System.Text.StringBuilder bld    = new System.Text.StringBuilder();
            Exception inner = ex.InnerException;

            stream.WriteLine("==============================================================================");
            stream.WriteLine(System.DateTime.Now.ToString() + "Ha ocurrido una excepción: " + ex.GetType().FullName);
            stream.WriteLine(ex.Message);
            if (inner != null)
            {
                stream.WriteLine("Inner Exception: " + inner.ToString());
            }
            if (ex.GetType() == typeof(System.Data.SqlServerCe.SqlCeException))
            {
                System.Data.SqlServerCe.SqlCeException sqlex = null;
                //INSTANT C# NOTE: Commented this declaration since looping variables in 'foreach' loops are declared in the 'foreach' header in C#:
                //			System.Data.SqlServerCe.SqlCeError err = null;
                sqlex = (System.Data.SqlServerCe.SqlCeException)ex;

                // Enumerate each error to a message box.
                foreach (System.Data.SqlServerCe.SqlCeError err in sqlex.Errors)
                {
                    stream.WriteLine(" Error Code: " + err.HResult.ToString("X"));
                    stream.WriteLine(" Message   : " + err.Message);
                    stream.WriteLine(" Minor Err.: " + err.NativeError);
                    stream.WriteLine(" Source    : " + err.Source);

                    // Retrieve the error parameter numbers for each error.
                    //INSTANT C# NOTE: Commented this declaration since looping variables in 'foreach' loops are declared in the 'foreach' header in C#:
                    //				int numPar = 0;
                    foreach (int numPar in err.NumericErrorParameters)
                    {
                        if (0 != numPar)
                        {
                            stream.WriteLine(" Num. Par. : " + numPar);
                        }
                    }

                    // Retrieve the error parameters for each error.
                    //INSTANT C# NOTE: Commented this declaration since looping variables in 'foreach' loops are declared in the 'foreach' header in C#:
                    //				string errPar = null;
                    foreach (string errPar in err.ErrorParameters)
                    {
                        if (string.Empty != errPar)
                        {
                            bld.Append(("\r" + " Err. Par. : " + errPar));
                        }
                    }
                }
            }
            stream.WriteLine("Stack Trace: " + ex.StackTrace.ToString());
            stream.Close();
        }
コード例 #2
0
ファイル: Helper.cs プロジェクト: chukwuemeka/SqlCeToolbox
        public static string ShowErrors(System.Data.SqlServerCe.SqlCeException e)
        {
            StringBuilder bld   = new StringBuilder();
            Exception     inner = e.InnerException;

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

            if (null != inner)
            {
                bld.Append("\nInner Exception: " + inner.ToString());
            }
            if (e.Errors != null)
            {
                System.Data.SqlServerCe.SqlCeErrorCollection errorCollection = e.Errors;
                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);
                        }
                    }
                }
            }
            return(bld.ToString());
        }
コード例 #3
0
 internal static void ShowErrors(System.Data.SqlServerCe.SqlCeException e)
 {
     System.Windows.Forms.MessageBox.Show(ErikEJ.SqlCeScripting.Helper.ShowErrors(e));
 }
コード例 #4
0
        static void Main()
        {
            String strExePath = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;

            ExeDir = strExePath.Substring(0, strExePath.LastIndexOf('\\') + 1);


            //ContractSelector.LoadGraphicsResources();
            //ContractSelector.SetCoordinates();



            // ------------------ start: XML ------------------
            if (System.IO.File.Exists(Program.ExeDir + "BridgeNote.xml") == false)
            {
                MessageBox.Show("Не найден файл BridgeNote.xml!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                return;
            }
            String            strDBPath        = "";
            String            strTempDir       = "";
            String            strDBPath_final  = "";
            String            strTempDir_final = "";
            bool              absDBPath        = true;
            bool              absTempDir       = true;
            bool              useTempDir       = false;
            XmlReaderSettings xml_settings     = new XmlReaderSettings();

            xml_settings.ConformanceLevel = ConformanceLevel.Fragment;
            xml_settings.IgnoreWhitespace = true;
            xml_settings.IgnoreComments   = true;
            XmlParserContext xml_context = new XmlParserContext(null, null, null, XmlSpace.Default, System.Text.Encoding.Default);
            XmlReader        xml_reader  = null;

            try
            {
                xml_reader = XmlReader.Create(Program.ExeDir + "BridgeNote.xml", xml_settings, xml_context);
                xml_reader.Read();
                xml_reader.ReadStartElement("Settings");
                xml_reader.ReadStartElement("Database");
                if (xml_reader.IsStartElement("File"))
                {
                    strDBPath = xml_reader.GetAttribute("path");
                    if (strDBPath == null || strDBPath.Length == 0)
                    {
                        xml_reader.Close();
                        MessageBox.Show("Не указан путь к файлу БД!", "BridgeNote.xml", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }

                    try
                    {
                        absDBPath = bool.Parse(xml_reader.GetAttribute("absolute"));
                    }
                    catch (Exception e)
                    {
                        xml_reader.Close();
                        MessageBox.Show("Ошибка в Settings.Database.File.absolute:\n" + e.Message, "BridgeNote.xml", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }
                }
                else
                {
                    xml_reader.Close();
                    MessageBox.Show("Не найден тег File!", "BridgeNote.xml", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }
                xml_reader.Skip();

                if (xml_reader.IsStartElement("TempDir"))
                {
                    try
                    {
                        useTempDir = bool.Parse(xml_reader.GetAttribute("use"));
                    }
                    catch (Exception e)
                    {
                        xml_reader.Close();
                        MessageBox.Show("Ошибка в Settings.Database.TempDir.use:\n" + e.Message, "BridgeNote.xml", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }

                    try
                    {
                        absTempDir = bool.Parse(xml_reader.GetAttribute("absolute"));
                    }
                    catch (Exception e)
                    {
                        xml_reader.Close();
                        MessageBox.Show("Ошибка в Settings.Database.TempDir.absolute:\n" + e.Message, "BridgeNote.xml", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }

                    strTempDir = xml_reader.GetAttribute("path");
                    if (useTempDir && (strTempDir == null || absTempDir && strTempDir.Length == 0))
                    {
                        xml_reader.Close();
                        MessageBox.Show("Не указана временная папка для БД!", "BridgeNote.xml", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }
                }
                else
                {
                    xml_reader.Close();
                    MessageBox.Show("Не найден тег TempDir!", "BridgeNote.xml", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }
                xml_reader.Skip();
                xml_reader.ReadEndElement();
                xml_reader.ReadEndElement();
            }
            catch (XmlException e)
            {
                if (xml_reader != null)
                {
                    xml_reader.Close();
                }
                MessageBox.Show(e.Message, "BridgeNote.xml", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                return;
            }

            xml_reader.Close();
            // ------------------ end: XML ------------------



            strDBPath_final  = (absDBPath ? strDBPath : (Program.ExeDir + strDBPath));
            strTempDir_final = (useTempDir ? (absTempDir ? strTempDir : (Program.ExeDir + strTempDir)) : "");

            // Проверить временную папку
            if (useTempDir && System.IO.Directory.Exists(strTempDir_final) == false)
            {
                MessageBox.Show("Неправильно указана временная папка для БД!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                return;
            }

            // Инициализировать строку подключения
            DB.InitializeConnectionString(strDBPath_final, strTempDir_final);

            // Создать БД, если нужно
            if (System.IO.File.Exists(strDBPath_final) == false)
            {
                if (MessageBox.Show("База данных не найдена!\nСоздать новую БД и проинициализировать ее?", "db create", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                {
                    if (DB.CreateDatabase(strDBPath_final) == false)
                    {
                        return;
                    }
                    DB.CreateTables(false);
                    DB.Disconnect();
                }
                else
                {
                    return;
                }
            }

            // Подключиться к базе данных
            DB.ReConnect();

            // Следить за подключением
            DB.sqlConnection.StateChange += new StateChangeEventHandler(sqlConnection_StateChange);


            // Запуск главной формы, большой try-catch если DEBUG
#if DEBUG
            try
            {
                Application.Run(MainForm = new Form1());
            }
            catch (Exception e)
            {
                System.IO.StreamWriter sw = System.IO.File.AppendText(Program.ExeDir + "debug.txt");
                sw.Write(DateTime.Now.ToString() + "\n");
                sw.Write(e.Message + "\n");
                sw.Write(e.StackTrace + "\n");
                if (e.GetType() == typeof(System.Data.SqlServerCe.SqlCeException))
                {
                    System.Data.SqlServerCe.SqlCeException ex = (System.Data.SqlServerCe.SqlCeException)e;
                    sw.Write("[SQL] NativeError = " + ex.NativeError + "\n");
                    for (int i = 0; i < ex.Errors.Count; i++)
                    {
                        sw.Write("[SQL_err_" + i + "] " + ex.Errors[i].Message + " * " + ex.Errors[i].NativeError + "\n");
                    }
                }
                sw.Write("-------------" + "\n");
                sw.Close();
                throw;
            }
#else
            Application.Run(MainForm = new Form1());
#endif
        }