[英]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.