asp.net sql server错误消息
我已经开发了一个建模系统使用SQLServer与ASP.NET(VB)前端 前端用于数据输入,在SQLServerManagementStudio中运行一些非常丰富的过程来运行计算 然而,该系统将被生产化,我将失去对实时后端的访问。因此,这些过程需要从ASP.NET站点运行 我担心的是,我将无法跟踪计算中出现的任何错误asp.net sql server错误消息,asp.net,sql,sql-server,vb.net,Asp.net,Sql,Sql Server,Vb.net,我已经开发了一个建模系统使用SQLServer与ASP.NET(VB)前端 前端用于数据输入,在SQLServerManagementStudio中运行一些非常丰富的过程来运行计算 然而,该系统将被生产化,我将失去对实时后端的访问。因此,这些过程需要从ASP.NET站点运行 我担心的是,我将无法跟踪计算中出现的任何错误 当SQL Server过程在ASP.NET网页的SSMS中运行时,是否有方法显示这些错误和/或当前显示的任何消息更新?首先,您应该引入正确的错误处理 您可以使用其他库,如将错误写
当SQL Server过程在ASP.NET网页的SSMS中运行时,是否有方法显示这些错误和/或当前显示的任何消息更新?首先,您应该引入正确的错误处理 您可以使用其他库,如将错误写入文件或任何其他源 NET还有一个内置的机制来检索最新的错误(Trace.axd)
您可以找到有关ASP.NET跟踪的更多信息。我不确定这是正确的方法,但我正在这样做 创建如下函数:
//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
{
//do my sql....
//.............
{
catch(Exception ex)
{
logError(ex);
}
在asp.net中查看日志。
创建一个页面并读取日志文件
注:我很高兴看到专家对这种方法的评论。
谢谢
快乐编码:)@user2417642:需要更多帮助吗?