简体   繁体   English

VB6与C#以不同顺序返回的SQL结果集

[英]SQL result set returned in different order for VB6 vs. C#

I am working on an old VB6.0 application that is being converted to C#. 我正在将旧的VB6.0应用程序转换为C#。 There are a number of SQL Server Views that are queried in the application. 在应用程序中查询了许多SQL Server视图。 I am passing the same SELECT statements in VB6.0 and C# to query the Views. 我在VB6.0和C#中传递相同的SELECT语句以查询视图。 I am also providing exactly the same WHERE clause in each language, and no ORDER BY clause. 我还在每种语言中提供了完全相同的WHERE子句,并且没有提供ORDER BY子句。 The views do contain their own ORDER BY clauses. 视图确实包含它们自己的ORDER BY子句。

In VB6.0, the result set consistently comes back in the same order, and in C# the result set consistently comes back in the same order. 在VB6.0中,结果集始终以相同顺序返回,而在C#中,结果集始终以相同顺序返回。 However, the orders returned to VB6.0 and C# do not match. 但是,返回到VB6.0和C#的订单不匹配。 I can query through VB6.0 and then query a few seconds later through C#, and the result sets are in different orders. 我可以通过VB6.0查询,然后在几秒钟后通过C#查询,结果集的顺序不同。

What could be causing the result set orders to be different? 是什么导致结果集顺序不同? I am needing to compare some output files generated from the new C# code to the VB6.0 code for validation, so I would like to either have the result sets come back in the same order for both, or at least understand why the result set orders do not match between VB6.0 and C#, but always match each other when called from the same language. 我需要将新C#代码生成的某些输出文件与VB6.0代码进行比较,以进行验证,因此我想让结果集以相同的顺序返回,或者至少了解为什么要使用结果集VB6.0和C#之间的顺序不匹配,但是从相同语言调用时,它们始终彼此匹配。

If you don't specify an ORDER BY you are never guaranteed what order the records come back in. 如果您未指定ORDER BY ,则无法保证记录会以什么顺序返回。

The order may usually come back in an order related to a clustered index, or some other characteristic of the data/schema. 该顺序通常可以以与聚簇索引或数据/架构的某些其他特征相关的顺序返回。 But it can change, without warning, or reason that you can perceive. 但是它可以更改,而不会发出警告或您可以察觉的理由。
- It might be due to which cores are or are not busy -可能是由于哪个核心忙或不忙
- It might be due to the interface you use with the SQL Server -这可能是由于您与SQL Server一起使用的界面
- It might be due to the records that were most recently introduced -可能是由于最近引入的记录
- Or fragmentation -或碎片
- Or caching of tables/results -或缓存表格/结果
- Or a patch on the SQL Server or OS -或SQL Server或OS上的补丁


If the order matters, specify an ORDER BY on the final/outermost query . 如果顺序很重要,请在最终查询/最外查询中指定ORDER BY。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM