very strange bug in production processing

T

Trapulo

I've a simple .NET 3.5 / ASP.NET application that runs well on development
server (Win 2008 x64) and with strange behavor in production (Win 2003 x86).
Basically this procedure gets some rows from a stored procedure (SQL
Server). A row has two coloms: an ID (int32) and a text.
The procedure may process every row and create a string with all text fields
values concatenates, using a standard stringbuilder. Very simple. This is
core code:

Dim data As DataTable = GetData()

Dim output As New Text.StringBuilder
For Each r As DataRow In data .Rows
output .Append(CStr(r("TextField")).Trim)
output .Append(" "c)
Next
result = output.ToString

In production, every time I have more than 25 output rows, I have this
sequence in output string:
- data from row #1
- data from row #26
- data from row #2
- data from rows #3....#25
- data from rows #27....

Some other times it's similar, but instead of having in second position
always the row #26, I have the last but one of original data.

So, if my sql output was:
1 A
2 B
3 C
......
24 D
25 E
26 F
28 G

in development I have an output like ABC....DEFG....
and in production I have AFBC...DEG...

Same datbases, same code!

The problem occurs either I run the procedure from ASP.NET, that from a
dummy console application I can write to run it as test.

I've tested via SQL Profiler and query analyzer that production and
development SQL Servers are returning same data: same row number, same ID,
same text fields. The problem is in .NET code, but it's so strange!


anyone can help me?
 
A

Allen Chen [MSFT]

Hi Trapulo,

Trapulo==================================================
Same datbases, same code!
==================================================

If so it's really strange. Could you send me a repro for me to test? Please
send me the database as well. In addition please provide the following
information:

" Is your database server Win 2003 x86? Is it on the web server machine?
" How about the client side? Did you test it on the same machine? What's
the client side's environment?

My email is (e-mail address removed) update here after sending the
project in case I missed that email.

If it really affects your project (generally we don't care the order of the
rows in DataTable because we use it's DefaultView in most cases) I think
you can sort the DataTable.DefaultView by ID after data is retrieved. To
sort the DataView ( DataTable.DefaultView is a DataView) please refer to:
http://msdn.microsoft.com/en-us/library/system.data.dataview.sort.aspx

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

Trapulo

Allen Chen said:
Hi Trapulo,

Hello Allen
Trapulo==================================================
Same datbases, same code!
==================================================

If so it's really strange. Could you send me a repro for me to test?
Please
send me the database as well.

I've big problems making this. DB is about 350MB, and original source code
is a complex solution with about 10 projects and a lot of code.. :(
And it's not easy to create a simpler repro too, I think, because the
problem is not constant and it doesn't appear in development.
In addition please provide the following
information:
" Is your database server Win 2003 x86?
Yes

Is it on the web server machine?
Yes

" How about the client side? Did you test it on the same machine? What's
the client side's environment?

Do you mean "development machine"? This is a single PC with Win2008 x64 and
SQL on same machine.
My email is (e-mail address removed) update here after sending the
project in case I missed that email.

If it really affects your project (generally we don't care the order of
the
rows in DataTable because we use it's DefaultView in most cases) I think
you can sort the DataTable.DefaultView by ID after data is retrieved. To
sort the DataView ( DataTable.DefaultView is a DataView) please refer to:
http://msdn.microsoft.com/en-us/library/system.data.dataview.sort.aspx

This can be a good solution, if it works always without unexpected results
(and doesn't slow dowm performance). Currently, the only problem is that the
field that result may be ordered by is not returned by the stored procedure.
However I can add it (it's an integer) to output and then try to (re)order
results in ADO.NET before using them.
I'll try this then I reply here when I know it this solves the problem or
not, ok?

thanks
 
T

Trapulo

Allen Chen said:
If it really affects your project (generally we don't care the order of
the
rows in DataTable because we use it's DefaultView in most cases) I think
you can sort the DataTable.DefaultView by ID after data is retrieved. To
sort the DataView ( DataTable.DefaultView is a DataView) please refer to:
http://msdn.microsoft.com/en-us/library/system.data.dataview.sort.aspx

Hello again Allen,
I've tried this and discovered that the problem is not with DataTable, but
(I think) in TextBuilder.
What I did:
1- ordered DefaultView and used it insteaf of base DataTable. Same result.
2- inserted a debug code that logs records that the For Each is processing.
Than I compared log with records reported by SQL Server: they are same! So,
the for each is processing rows in same order as I aspect, and as SQL Server
returns.
3- so I inserted an other debug code, that logs the stringbuilder output
after the for each. The string output on production server is different that
the one on development!

I don't know what to say... :((

I'll send to you output data in email.

Thanks
 
A

Allen Chen [MSFT]

Hi Trapulo,

Thanks for the clues. However, I didn't see your email. Have you sent it?
If not, since you've discovered that it's caused by the StringBuilder you
can fill the DataTable beforehand. We can create a minimal repro in this
way.

My email is (e-mail address removed) update here after sending the
project in case I missed that email.

Regards,
Allen Chen
Microsoft Online Support
 
T

Trapulo

Allen Chen said:
Hi Trapulo,

Thanks for the clues. However, I didn't see your email. Have you sent it?
If not, since you've discovered that it's caused by the StringBuilder you
can fill the DataTable beforehand. We can create a minimal repro in this
way.

I suspended it in my "draft" folder, because I'm performing some additional
tests before. It's too strange, really really strange as bug, so I want to
be sure that I've tested every dummy option. When I finish, I'll send to you
that email with logs.

Thanks
 
T

Trapulo

I got it!

The problem wasn't related to datatable or StringBuilder. Later in
procedure, there was something wrong in sql to objects statement used to
inizialize this for each:

For Each pStep As step In Steps.Skip(1)

I've changed as

For Each pStep As step In (From p As step In Steps Order By
p.SequencePosition).Skip(1)

The linq Skip was changing collection order (Steps was already ordered by
SequrencePosition), so that results was not based on the original collection
order!

Why this? I don't know very well Linq, but it sounds strange...

thanks for your assistance, Allen!
 
A

Allen Chen [MSFT]

Hi Trapulo,

Based on my test the SQL generated by Linq Skip will not change the order.
Could you remove the Skip in your code to see if the order is still changed?

Could you send me a repro project? You can create a simple DataBase and a
new project to create the demo.

My email: (e-mail address removed)

Regards,
Allen Chen
Microsoft Online Support
 
T

Trapulo

I'm working with Linq to Objects, not linq to sql, so there isn't any
generated SQL...
Steps is a custom collection, where I just need to skip first item in for
each.

thanks
 
A

Allen Chen [MSFT]

Hi Trapulo,

This is my test code. Based on the test, the Skip will not change the
order. Could you test it to see if it's true? Could you send me a demo that
can reproduce this problem?

Aspx:
<form id="form1" runat="server">
<div>
Init
<asp:GridView ID="GridViewInit" runat="server">
</asp:GridView>
Skip
<asp:GridView ID="GridViewSkip" runat="server">
</asp:GridView>
Order
<asp:GridView ID="GridViewOrder" runat="server">
</asp:GridView>

Order+Skip
<asp:GridView ID="GridViewOrderSkip" runat="server">
</asp:GridView>
</div>
</form>
Aspx.vb:
Public Class MyStep
Private _myid As Integer
Private _sequenceposition As Integer
Public Property MyID() As Integer
Get
Return _myid
End Get
Set(ByVal value As Integer)
_myid = value
End Set
End Property
Public Property SequencePosition() As Integer
Get
Return _sequenceposition
End Get
Set(ByVal value As Integer)
_sequenceposition = value

End Set
End Property
End Class

Partial Public Class _Default
Inherits System.Web.UI.Page
Shared r As Random = New Random()
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'init
Dim list As List(Of MyStep) = New List(Of MyStep)()
For i As Integer = 0 To 9

Dim s As MyStep = New MyStep()
s.MyID = i
s.SequencePosition = r.Next(0, 100)
list.Add(s)
Next i
Me.GridViewInit.DataSource = list
Me.GridViewInit.DataBind()
'skip
Dim listafterskip As List(Of MyStep) = New List(Of MyStep)()
For Each s As MyStep In list.Skip(1)
listafterskip.Add(s)
Next s
Me.GridViewSkip.DataSource = listafterskip
Me.GridViewSkip.DataBind()

'order
Dim listorder As List(Of MyStep) = New List(Of MyStep)()
For Each s As MyStep In (From p As MyStep In list Order By
p.SequencePosition)
listorder.Add(s)
Next s
Me.GridViewOrder.DataSource = listorder
Me.GridViewOrder.DataBind()

'order + skip
Dim listorderskip As List(Of MyStep) = New List(Of MyStep)()
For Each s As MyStep In (From p As MyStep In list Order By
p.SequencePosition).Skip(1)
listorderskip.Add(s)
Next s
Me.GridViewOrderSkip.DataSource = listorderskip
Me.GridViewOrderSkip.DataBind()
End Sub
End Class



Regards,
Allen Chen
Microsoft Online Support
 
A

Andrew Morton

Trapulo wrote:
<data not in order from SQL query>

Are you aware that SQL Server is free to return the results in any order
*unless* you specify an ORDER BY clause?

Andrew
 
A

Allen Chen [MSFT]

Hi Trapulo,

Do you have any progress on this issue? Have you sent me the repro?

Regards,
Allen Chen
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top