我有这个我知道会被命中的代码,因为插入正在完成:
Response.Write("<!-- Made it just before INSERT INTO CustomerCategoryLog -->")
Dim query As String = String.Empty
query &= "INSERT INTO CustomerCategoryLog (MemberNo, Unit, Custno, "
query &= "Category, Subcategory, BeginDate, "
query &= "EndDate, ChangedBy, ChangedOn) "
query &= "VALUES (@MemberNo, @Unit, @Custno, @Category, @Subcategory, @BeginDate, @EndDate, @ChangedBy, @ChangedOn)"
Using conn As New SqlConnection("SERVER=PROSQL05;DATABASE=cpsdata;UID=sa;PWD=sqlsql")
Using comm As New SqlCommand()
Response.Write("<!-- Made it into the using comm As New SqlCommand() block -->")
With comm
.Connection = conn
.CommandType = CommandType.Text
.CommandText = query
.Parameters.Add("@MemberNo", SqlDbType.NVarChar).Value = MemberNo
.Parameters.Add("@Unit", SqlDbType.NVarChar).Value = Unit
.Parameters.Add("@Custno", SqlDbType.NVarChar).Value = CustNo
.Parameters.Add("@Category", SqlDbType.NVarChar).Value = Category
.Parameters.Add("@Subcategory", SqlDbType.NVarChar).Value = Subcategory
.Parameters.Add("@BeginDate", SqlDbType.DateTime).Value = Date.Now()
.Parameters.Add("@EndDate", SqlDbType.DateTime).Value = Date.Now().AddDays(365)
.Parameters.Add("@ChangedBy", SqlDbType.NVarChar).Value = Environment.UserName
.Parameters.Add("@ChangedOn", SqlDbType.DateTime).Value = Date.Now()
End With
Try
Response.Write("<!-- Made it into the try block -->")
conn.Open()
comm.ExecuteNonQuery()
Catch '(ex as SqlException)
Response.Write("<!-- Made it into the catch block -->")
End Try
End Using 'comm
End Using 'conn
然而,正如“查看源代码”所示,没有一个 Response.Write() 被呈现到页面上。
他们为什么不呢?在以前的地方,使用相同的语法编写了注释/调试消息:
Response.Write("<!-- IsNewBusiness after NOT adoRS.EOF check = " & CStr(IsNewBusiness) & " -->")
为什么后续调用 Response.Write() 什么都不做?
更新
Web.Config中有一个“system.diagnostics”部分,内容如下:
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog" />
<!-- Uncomment the below section to write to the Application Event Log -->
<add name="EventLog" />
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="eServices" />
</sharedListeners>
</system.diagnostics>
如您所见,有一个“sharedListeners”小节,但据我所知,它并没有清除它们......
更新 2
这是我在添加“HttpContext.ApplicationInstance.Context”之后得到的。到“Trace.Write(”:
Server Error in '/EMS/customerreportingnet' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30469: Reference to a non-shared member requires an object reference.
Source Error:
Line 184: ' Put the Category Table insert here, too...
Line 185: ' Beginning of SQL Insert code added 3/6/2017 - if not reached, move it above the "END IF"
Line 186: HttpContext.ApplicationInstance.Context.Trace.Write("<!-- Made it just before INSERT INTO CustomerCategoryLog -->")
Line 187: Dim query As String = String.Empty
Line 188: query &= "INSERT INTO CustomerCategoryLog (MemberNo, Unit, Custno, "
Source File: C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_entry.aspx Line: 186
UDPATE 3
一个(对我来说非常)奇怪的是,当我得到 trace.axd 时,它没有列出有问题的文件——我在其中插入了对 Trace.axd 的调用:
但我在那个页面上(虽然它没有显示在 URL 中,仍然是 http://localhost/EMS/customerreportingnet),当我将“/trace.axd”附加到 URL 并按 Enter 键时。
为什么文件不会出现在列表中?
如果我从该页面“查看源代码”,我确实会看到它的一些输出,例如“”
因此 custmaint_entry.aspx 正在被访问 - “查看源代码”窗格中的 URL 也可以看到: