Why would this event handler code cause a Object reference not set to an instance of an object. Error (only present on live server, ok on dev)?
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 开发者_如何学C= 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.
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.
精彩评论