SP-developer
SP-developer

Reputation: 1

asp.net repeater control error assigning datatable as datasource

i have asp.net app, works fine on windows 10 IIS 7, but fails on MS Server 2012 R2, IIS 6.2(build 9200)

Using a repeater to show formatted rows of a sql server database query. It retrieves results in dataset, loop through dataset, formatting data one row at a time and loading each row into a datatable. When I set the repeater DataSource to my datatable, it blows with: Object reference not set to an instance of an object.

I have VS 2022 on two different Win 10 machines - works fine on both, run for framework 4.6.1. I install the web application on my client's Win Server 2012R2, it blows. The app has several aspx pages that work fine on the 2012 server, just this particular page using a repeater with a datatable datasource is bad.

Another page with repeater works fine in 2012, it uses the raw results of a query loaded into a dataset, then set the repeater datasource to the dataset and binds - no problem.


  

Overview: create dt as new datatable, add one string column to dt create ds as dataset Execute Query, load into ds dataset loop through rows of ds for each row, do some analysis add new row to dt set the column of dt to a formatted string value to end of ds repeaterobj.DataSource = dt --- this is where it blows, obj ref no set to instance of obj

This code works fine on Win 10 box, IIS 7 and IIS express in VB 2022 environment.

Again, another page on 2012 server works using repeater, but datasource is the dataset instead of a datatable.

I really appreciate your help! Why would the datatable source fail when the dataset source works? Is it OS 2012 issue?

vb code and aspx page snippets

           Using dbConn As New SqlConnection(SQLConnString)
                dbConn.Open()
                SQLString = "SELECT col1,col2 FROM table"

                Dim daSQLData As New SqlDataAdapter(SQLString, dbConn)
                dsData = New DataSet()
                dt.Columns.Add("StreamInfo", Type.GetType("System.String"))

                daSQLData.Fill(dsData, "data")

                If dsData.Tables("data").Rows.Count = 0 Then
                    dt.Rows.Add()
                    dt.Rows(dt.Rows.Count - 1)("StreamInfo") = "No New Streams"
                Else
                    For i = 0 To dsData.Tables("NewStreams").Rows.Count - 1
                        DBDataRow = dsData.Tables("NewStreams").Rows(i)
                        WSID = DBDataRow("col1")
                        LabelID = DBDataRow("col2")

                        dt.Rows.Add()
                        dt.Rows(dt.Rows.Count - 1)("StreamInfo") = "<a href=""ReviewNewStream.aspx?WSID=" & WSID & """>" & LabelID & "</a>"
                    Next
                End If

                rptrNewStreams.DataSource = dt      'error here, does not execute this line
                rptrNewStreams.DataBind()
            End Using
            
            aspx page
            
            <asp:Panel ID="pnlReviewNew" runat="server">
               <asp:Repeater ID="rptrNewStreams" runat="server">  
                 <HeaderTemplate>  
                    <ul>
                 </HeaderTemplate>  
                <ItemTemplate>  
                    <li><%#Eval("StreamInfo") %></li>
                </ItemTemplate>
                <FooterTemplate>
                    </ul>
                </FooterTemplate>
               </asp:Repeater> 
            </asp:Panel>
        

Upvotes: 0

Views: 159

Answers (1)

Albert D. Kallal
Albert D. Kallal

Reputation: 48989

Are you deploying a "asp.net web site", or are you deploying a "asp.net web site applicaton" ? Its possible that some code is setup to use Rosyln compiler, and you (often) don't have Rosyln on standard IIS installs.

But, this issue much depends on if you are deploying source code to the web site, and letting IIS compile your code as opposed to letting and having visual studio compile your code.

If you deploying as a asp.net web site application, then I suggest moving any code you have out of the app_code folder, and re-name the folder as myCode or some such. You then right click on any code module in myCode and choose compile in the build action (property sheet) for each class/code module in that myCode folder.

Also, you don't show how/where you are creating/getting SQLConnString.

Is that string from a global code module, and is shared to all code? Remember, any global vars + code not only is shared between all users, but also the values of such static code modules. As a result, this is a ok setup as long as those variables are not attempted to be persisted between post-backs.

Since it seems no compile errors are occurring, then you can scratch off your list the 1st suggestion about code compile issues.

So, next up would be issues of persisting values - like the connection string setting you have - where/how does that value get set in your code?

However, if the one page ALWAYS fails, even with just one user on the system, then again, this suggests that either the data has some nulls or some values that cause the code to go sideways, or there is some persisting of variables in code. (however, as noted, if the one-page code ALWAYS fails, then this is un-likely due to persisting of values or multi-user operations causing this failure).

It is BEYOND difficult to debug such a issue on this Q+A forum, and small details such as does this page always fail, or fail with multiple users are one of many details that makes tracking this issue down beyond difficult in such a Q+A environment. As such, we can only make above types of general suggestions.

If you can deploy as a web site application, and also NOT use app_code, then that would 100% eliminate differences in the build/compile process, since then before deploying, the compile of code is occurring with your copy of VS, and occurs before deploying, and such code is thus not compiled by IIS.

Upvotes: 0

Related Questions