简体   繁体   English

asp.net SQL Server错误消息

[英]asp.net sql server error messages

I have developed a modelling system using SQL Server with an ASP.NET(VB) front end. 我已经开发了使用SQL Server和ASP.NET(VB)前端的建模系统。

The front end is used for data inputs and some pretty meaty procedures are run in SQL Server Management Studio to run the calculations. 前端用于数据输入,并且在SQL Server Management Studio中运行一些非常繁琐的过程来运行计算。

However the system is going to be productionalised and i am going to lose access to the Live backend. 但是,该系统将投入生产,而我将无法访问Live后端。 Therefore the procedures will need to be run from the ASP.NET site. 因此,将需要从ASP.NET站点运行这些过程。

My concern is that i will not be able to track any errors that occur in the calculations. 我担心的是,我将无法跟踪计算中发生的任何错误。

Is there a way to display these errors &/or any message updates that currently display when the SQL Server procedures are run in SSMS on an ASP.NET webpage? 当在ASP.NET网页上的SSMS中运行SQL Server过程时,是否可以显示这些错误和/或当前显示的任何消息更新?

First of all, you should introduce proper error handling. 首先,您应该引入适当的错误处理。

You can use additional libraries like log4net to write error to a file, or any other source. 您可以使用log4net之类的其他库将错误写入文件或任何其他源。

Also .NET has a built-in mechanism to retrieve latest errors (Trace.axd). .NET还具有一个内置的机制来检索最新错误(Trace.axd)。

You can find more info on ASP.NET Tracing here . 您可以在此处找到有关ASP.NET跟踪的更多信息。

I am not sure this is right way but I am doing like that. 我不确定这是正确的方法,但是我正在那样做。

create a function like: 创建一个像这样的函数:

        //Log error
    static public void logError(Exception erorr)
    {
        //create/append file with current date as file name
        string logfile = DateTime.Now.ToString("yyyyMMdd") + ".log";
        logfile = Global.logpath + logfile; //logpath is a full folder path defined it the Global.cs file to hold the log files.
        using (StreamWriter sw = File.AppendText(logfile))
        {
            sw.Write("\r\nLog Entry : ");
            sw.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString());
            sw.WriteLine("  :");
            sw.WriteLine("  :Message :{0}", erorr.Message);
            sw.WriteLine("  :Source  :{0}", erorr.Source);
            if (erorr.InnerException != null)
                sw.WriteLine("  :Inner Ex:{0}", erorr.InnerException.Message);

            System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(erorr, true);
            var stackFrame = trace.GetFrame(trace.FrameCount - 1);
            sw.WriteLine("  :");
            sw.WriteLine("  :Stack   :");
            sw.WriteLine("           :Line Number :{0}", stackFrame.GetFileLineNumber());
            sw.WriteLine("           :Source File :{0}", stackFrame.GetFileName());
            sw.WriteLine("-------------------------------");
        }
    }

then put your calculation in a try ... catch block. 然后将您的计算结果放入try ... catch块中。 Like 喜欢

try 
{
  //do my sql....
  //.............
{
catch(Exception ex)
{
   logError(ex);
}

To view the log in asp.net. 要查看asp.net中的日志。 Create a page and read the logfile. 创建一个页面并读取日志文件。

NB: I will be happy to see the comments from expert about this approach. 注意:我很高兴看到专家对这种方法的评论。 Thanks Happy Coding :) 谢谢快乐编码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM