为什么此事件处理程序代码会导致对象引用未设置到对象的实例。错误(仅出现在实时服务器上,在开发版上可以)?

发布于 2024-08-23 09:10:14 字数 1574 浏览 5 评论 0原文

这是按钮单击事件的代码;

  Protected Sub CompetenciesButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CompetenciesButton.Click
        Dim con As String = WebConfigurationManager.ConnectionStrings("foo").ToString()
        Dim selectedrow As String = Competencies.SelectedValue.ToString
        Dim s As String = "SELECT * from foo WHERE (" & selectedrow & " =1)"
        Dim DataAdapter As New SqlDataAdapter(s, con)
        Dim Result As New DataTable
        If Not IsNothing(DataAdapter) Then
            DataAdapter.Fill(Result)
            DataAdapter.Dispose()
        End If
        GV.DataSource = Result
        GV.DataBind()
        GV2.DataSource = Result
        GV2.DataBind()
    End Sub

这是堆栈:

[NullReferenceException: Object reference not set to an instance of an object.]
   administration_Search.CompetenciesButton_Click(Object sender, EventArgs e) +28
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

在 VS2008 中,一切都可以离线运行,但在发布后出现此错误。

谢谢。

Here is the code for the button click event;

  Protected Sub CompetenciesButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CompetenciesButton.Click
        Dim con As String = WebConfigurationManager.ConnectionStrings("foo").ToString()
        Dim selectedrow As String = Competencies.SelectedValue.ToString
        Dim s As String = "SELECT * from foo WHERE (" & selectedrow & " =1)"
        Dim DataAdapter As New SqlDataAdapter(s, con)
        Dim Result As New DataTable
        If Not IsNothing(DataAdapter) Then
            DataAdapter.Fill(Result)
            DataAdapter.Dispose()
        End If
        GV.DataSource = Result
        GV.DataBind()
        GV2.DataSource = Result
        GV2.DataBind()
    End Sub

Here is the stack:

[NullReferenceException: Object reference not set to an instance of an object.]
   administration_Search.CompetenciesButton_Click(Object sender, EventArgs e) +28
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

Everything works fine offline in VS2008 but I get this error after publishing.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雅心素梦 2024-08-30 09:10:14

您的 WebConfiguration 在开发版和上线版上是否相同?

如果实时服务器上缺少 foo 连接字符串,则 con 对象将设置为 null。

如果您仍然无法捕获它,请尝试包含一个 try/catch 块,在 try 之外设置一个字符串变量 progress,更新逻辑中的每一行,并记录错误以及进度的当前值。这应该有助于缩小问题发生的范围。

Is your WebConfiguration the same on both dev and live?

If you are missing the foo connection string on the live server, then the con object would be set to null.

And if you are still having trouble catching it, then try including a try/catch block, setting a string variable progress outside of try, updating it every line within the logic, and logging the error along with the current value of progress. This should help to narrow down where it is happening.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文