【发布时间】:2014-09-30 16:47:53
【问题描述】:
当我执行“DEBUG -> Start Debugging”和“DEBUG -> Start without Debugging”时,我在 VS2013 中得到了不同的堆栈跟踪。似乎外部异常正在被丢弃。
这是我执行“DEBUG -> Start Debugging”时得到的结果(注意外部异常):
EmgNet.Exceptions.SQLExecutionException: Incorrect syntax near 'Heights_xlsx'.
Failed while executing: 'IF OBJECT_ID('tempdb..#mapping_Heights_xlsx') IS NOT NULL DROP TABLE #mapping_Heights_xlsx' ---> System.Data.SqlClient.SqlException: Incorrect syntax near 'Heights_xlsx'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.EndExecuteNonQuery(IAsyncResult asyncResult)
at EmgNet.DataLib.ExecSql(String SqlText, IDbConnection& Connection, Int32 CommandTimeout, IDbTransaction& Transaction, String MultipleRowSeparator, Object FieldNames, SqlExecType ExecType) in C:\DevHome\TFS\Projects\DataLib.vb:line 4181
--- End of inner exception stack trace ---
at EmgNet.DataLib.ExecSql(String SqlText, IDbConnection& Connection, Int32 CommandTimeout, IDbTransaction& Transaction, String MultipleRowSeparator, Object FieldNames, SqlExecType ExecType) in C:\DevHome\TFS\Projects\DataLib.vb:line 4207
at EmgNet.DataHandler.ExecSql(String SqlText, IDbConnection& Connection, Int32 CommandTimeout, IDbTransaction& Transaction, String MultipleRowSeparator, Object FieldNames, SqlExecType ExecType) in C:\DevHome\TFS\Projects\DataHandler.vb:line 1248
at EmgNetExt.SimpleFileImporterMapper.LoadFileInternal(String file) in C:\DevHome\TFS\Projects\DataLoaderWithMapper\SimpleFileImporterMapper.vb:line 36
at EmgNetExt.AFileImporterMapper.LoadFile(String file) in C:\DevHome\TFS\Projects\DataLoaderWithMapper\AFileImporterMapper.vb:line 19
at EmgNetExt.frmDataLoaderWithMapper.LoadFile() in C:\DevHome\TFS\Projects\DataLoaderWithMapper\frmDataLoaderWithMapper.vb:line 130
at EmgNetExt.frmDataLoaderWithMapper.frmDynamicDataLoader_Shown(Object sender, EventArgs e) in C:\DevHome\TFS\Projects\DataLoaderWithMapper\frmDataLoaderWithMapper.vb:line 55
at System.Windows.Forms.Form.OnShown(EventArgs e)
at System.Windows.Forms.Form.CallShownEvent()
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at frmStart.NewImportToolStripMenuItem_Click(Object sender, EventArgs e) in C:\DevHome\TFS\Projects\frmStart.vb:line 3358
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
这是我执行“DEBUG -> Start without Debugging”时得到的结果(注意没有外部异常):
System.Data.SqlClient.SqlException: Incorrect syntax near 'Heights_xlsx'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.EndExecuteNonQuery(IAsyncResult asyncResult)
at DataLib.ExecSql(String SqlText, IDbConnection& Connection, Int32 CommandTimeout, IDbTransaction& Transaction, String MultipleRowSeparator, Object FieldNames, SqlExecType ExecType) in C:\DevHome\TFS\Projects\DataLib.vb:line 4181
我很难理解为什么会发生这种情况。为什么使用调试器运行或不使用调试器运行时堆栈跟踪会发生变化?
【问题讨论】:
-
是否可以假设以两种不同的方式呈现相同的异常?
-
可能在没有调试器的情况下运行不包括所有调试信息。运行没有调试运行Release版本吗?如果是这样,您的发布配置是否包括创建 .pdf 文件?此外,可能正在进行优化,导致编译代码略有不同。
-
@ChrisDunaway,选择“Start without Debugging”不一定会运行 Release 版本(除非您特别选择了“Release”配置)。请参阅this link 了解是否启动调试的区别。