[英]asp.net sql server error messages
我已经开发了使用SQL Server和ASP.NET(VB)前端的建模系统。
前端用于数据输入,并且在SQL Server Management Studio中运行一些非常繁琐的过程来运行计算。
但是,该系统将投入生产,而我将无法访问Live后端。 因此,将需要从ASP.NET站点运行这些过程。
我担心的是,我将无法跟踪计算中发生的任何错误。
当在ASP.NET网页上的SSMS中运行SQL Server过程时,是否可以显示这些错误和/或当前显示的任何消息更新?
我不确定这是正确的方法,但是我正在那样做。
创建一个像这样的函数:
//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("-------------------------------");
}
}
然后将您的计算结果放入try ... catch
块中。 喜欢
try
{
//do my sql....
//.............
{
catch(Exception ex)
{
logError(ex);
}
要查看asp.net中的日志。 创建一个页面并读取日志文件。
注意:我很高兴看到专家对这种方法的评论。 谢谢快乐编码:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.