Results 1 to 7 of 7

Thread: Cannot get web app to work with MS Access databases

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    4

    Cannot get web app to work with MS Access databases

    I have two web pages that perform statistical calculations using data from MS Access tables. In VS 2019 it works fine. I have not been able to make it work after I deploy the pages to the web. I have rewritten the code using numerous approaches, but cannot get it to work. My latest is very simple, display the tables on the web page using GridView then select values from the Gridview but I am getting a null reference that I cannot get rid of. I had edited the webconfig and on and on.

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Cannot get web app to work with MS Access databases

    Well, a null reference error means that some object, somewhere in a line of code you're using is NULL or Nothing. What exactly that could be is anyone's guess at this point. It could be an object, it could be a database field, it could be the sun, it could be the North Star. Thing is, we don't know, since you didn't supply the problem code. So I don't know what help we can be. All I can suggest at this point is to remove the eels from your hovercraft and try again.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    4

    Re: Cannot get web app to work with MS Access databases

    Quote Originally Posted by techgnome View Post
    Well, a null reference error means that some object, somewhere in a line of code you're using is NULL or Nothing. What exactly that could be is anyone's guess at this point. It could be an object, it could be a database field, it could be the sun, it could be the North Star. Thing is, we don't know, since you didn't supply the problem code. So I don't know what help we can be. All I can suggest at this point is to remove the eels from your hovercraft and try again.

    -tg
    Thanks for the initial start, the coding is as follows:
    Code:
     Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
            Dim sLines1() As String, L1 As Integer
            sLines1 = Split(TextBox1.Text, vbCrLf)
            Dim sLines1check As String = sLines1(UBound(sLines1))
            Dim location1 As Integer = sLines1.Length - 1
            If sLines1check = "" Then
                Dim sLinesa(location1 - 1) As String
                Array.Copy(sLines1, 0, sLinesa, 0, location1)
                Dim Xinput11 = GetXinput1sLinesa(sLinesa)
                Dim xyCount1 As Integer = sLinesa.Length
                Dim Xinput22(xyCount1 - 1) As Single
                For L1 = 0 To UBound(Xinput11)
                    Xinput22(L1) = Xinput11(L1)
                Next
                Session("Xinput1") = Xinput11
                Session("Xinput2") = Xinput22
                Session("xyCount") = xyCount1
            Else
                Dim Xinput11() As String = sLines1
                For L1 = 0 To UBound(sLines1)
                    Xinput11(L1) = sLines1(L1)
                Next
                Dim xyCount1 As Integer = sLines1.Length
                Dim check As String = Xinput11(UBound(sLines1))
                Dim Xinput22(xyCount1 - 1) As Single
                For L1 = 0 To UBound(Xinput11)
                    Xinput22(L1) = Xinput11(L1)
                Next
                Session("Xinput1") = Xinput11
                Session("Xinput2") = Xinput22
                Session("xyCount") = xyCount1
            End If
            Dim Xinput1() As String = Session("Xinput1")
            Dim Yinput1() As String = Session("Yinput1")
            Dim Xinput2() As Single = Session("Xinput2")
            Dim xyCount As Integer = Session("xyCount")
            'Dim numofdata As Integer = xyCount
            Dim df1 As Integer = xyCount - 2
            Dim SqlDataSource1 As New DataSet
            Dim SqlDataSource2 As New DataSet
    
    #Disable Warning IDE0059 ' Unnecessary assignment of a value
            Dim conflevel As New Single
    #Enable Warning IDE0059 ' Unnecessary assignment of a value
    
            conflevel = GridView2.SelectedRow.Cells(1).Text
    
            'Dim studentt As String
            Dim studentt As New Single '= GridView1.SelectedRow.Cells(6).Text
            If conflevel = "t095" Then
                studentt = GridView1.SelectedRow.Cells(6).Text
                'studentt = GridView1.SelectedRow.Cells(conflevel).Text
            End If
    
    #Disable Warning BC42104 ' Variable is used before it has been assigned a value
            TextBox3.Text = studentt
    #Enable Warning BC42104 ' Variable is used before it has been assigned a value
            'Dim MyCount As Single
            'MyCount = 0
            Dim avgx, addn, Dev, AddDev, AvgDev, Stdev1, Stdev2, AddDev1 As Single
            'Dim Nx As Integer
    
            'Nx = "0"
            Dim I As Integer
            For L1 = 0 To UBound(Xinput1)
    #Disable Warning IDE0054 ' Use compound assignment
                addn = addn + Xinput1(L1)
    #Enable Warning IDE0054 ' Use compound assignment
            Next L1
            avgx = addn / xyCount
            TextBox4.Text = Format(avgx, "0.00000")
    
            For I = 0 To UBound(Xinput1)
                If xyCount <> 0 Then
                    Dev = Math.Abs(Xinput1(I) - avgx)
    #Disable Warning IDE0054 ' Use compound assignment
                    AddDev = AddDev + Dev
    #Enable Warning IDE0054 ' Use compound assignment
                End If
            Next I
    
            If AddDev <> 0 Then
                AvgDev = AddDev / xyCount
                ' TextBox31.Text = AvgDev
            End If
    
            For I = 0 To UBound(Xinput1)
                If xyCount <> 0 Then
                    Stdev1 = (Xinput1(I) - avgx) ^ 2
    #Disable Warning IDE0054 ' Use compound assignment
                    AddDev1 = AddDev1 + Stdev1
    #Enable Warning IDE0054 ' Use compound assignment
                End If
            Next I
    
            If avgx <> 0 And xyCount > 1 Then
                Stdev2 = Math.Sqrt(AddDev1 / (xyCount - 1))
                TextBox5.Text = Format(Stdev2, "0.00000")
                TextBox6.Text = Format((studentt * Stdev2) / Math.Sqrt(xyCount), "0.00000")
            End If
            Dim conlim As Single = TextBox6.Text
            TextBox7.Text = xyCount
            TextBox8.Text = Format(TextBox4.Text - TextBox6.Text, "0.00000")
            TextBox9.Text = Format(TextBox4.Text + conlim, "0.00000")
        End Sub
    
        'Private Function GetConnectionString() As String
        'Return "Provider = Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\bmham\source\repos\WebApplication1\WebApplication1\App_Data\Studentst1.mdb"
        'End Function
    
        'Private Function GetConnectionString() As String
        'Return "Provider = Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Studentst1.mdb"
        'End Function
    
        'Private Function GetConnectionString() As String
        'Return "Provider = Microsoft.ACE.OLEDB.12.0;Data Source=GridView1"
        'End Function
    
        'Protected Sub SqlDataSource2_Selecting(sender As Object, e As SqlDataSourceSelectingEventArgs)
    
        'End Sub
    
    End Class
    Last edited by si_the_geek; Apr 7th, 2021 at 01:10 PM. Reason: added Code tags

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Cannot get web app to work with MS Access databases

    Still, you didn't tell us which line of code is causing the Null reference. That's the place we need to start.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    4

    Re: Cannot get web app to work with MS Access databases

    Quote Originally Posted by wes4dbt View Post
    Still, you didn't tell us which line of code is causing the Null reference. That's the place we need to start.
    In VS2019 the code runs fine with no errors. Its when I run the page on the web server. I get back the same null reference error with the same line of code at line 134. I change the coding around and it always says at line 134. It is after I publish the page to the web server and run the page. If it was in VS I could solve the problem usually. Here is a copy of the error page I get:


    Server Error in '/WebApplication' Application.
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:


    [NullReferenceException: Object reference not set to an instance of an object.]
    WebApplication1.WebForm22.Button6_Click(Object sender, EventArgs e) in C:\Users\bmham\source\repos\WebApplication1\WebApplication1\Chap5-stat2.aspx.vb:134
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9780226
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3701.0

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    4

    Re: Cannot get web app to work with MS Access databases

    Perhaps I should pose this question in another way. I have coded the web page to get data from a MS Access database file. I was having trouble getting the code after deploying to the web to get the data from the database tables. I found that the sql was not working. I also found that when I used GridView the web page was getting the data from the tables and displaying on the web page. So, I turned to trying to select the data from the GridViews and that is the code above. But now I get this null reference.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Cannot get web app to work with MS Access databases

    Quote Originally Posted by ChemTech View Post
    I get back the same null reference error with the same line of code at line 134.
    If only there was a way that we could find out what line in the code you posted is that line 134. If there was someone who already knew that then they could tell us. Alas, I can't think of any such person.

    Regardless, NullReferenceExceptions are actually quite easy to diagnose. There are generally not may distinct references used on any one line of code so you can fairly easily test each one to determine which is Nothing. You can add code to do that and log the results, so you can still get that information outside the debugger. Once you know which reference is the issue, you can look backwards through the code to see where it should have been assigned a value. You can then add further code to check whether or not that's happening. If it's not then you can try to work out how and why that might be happening. We can help with that, if we are provided with all the relevant information. The most likely explanation is that your Production database contains different data to your Debug/Test database and you are incorrectly assuming that something exists when it might not. It's impossible to be more specific without you providing specific information.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width