从版本5.0.0升级到版本6.1.3时查询非常慢 [英] Query VERY slow on upgrade to version 6.1.3 from version 5.0.0

查看:60
本文介绍了从版本5.0.0升级到版本6.1.3时查询非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用实体框架5.0.0和SQL Server Express 2012的已发布应用程序。我们正在开发一个新版本的应用程序,并决定将SQL升级到2014,将实体框架升级到6.1.3 。现在对数据库的第一个查询减慢了我们的
应用程序加载时间20秒!同样不变的代码。

We have a released application using the entity framework 5.0.0 with SQL Server Express 2012. We are working on a new version of the app, and decided to upgrade SQL to 2014 and the Entity framework to 6.1.3. Now the first query to the database slows our application load time by 20 seconds!! Same unchanged code.

此代码部分需要5.4秒,其中RowId是主键。小表只有18行

使用 NxSummaryOnlyContainer
db =
new
NxSummaryOnlyContainer ()){
//选择摘要

   
var tss =( 来自
s
in db.TxSummaries

       ;         
orderby s.RowId
descending
//这将为我们提供最后一次治疗

               
选择 s)。取(1);
//只获取最上一行

       
经理 。AppLog.AddLogEntry( " SQL
查询完成"
);

此代码部分需要14秒才能完成

       
if ((tss!=
null )&&(tss.Count()> 0)){

           
TxSummary ts = tss.First();

           
经理 。AppLog.AddLogEntry( " SQL
获取第一个"
);

为了进一步复杂化我们在Windows 7嵌入式系统上运行此功能,并启用了文件库写入过滤器(驱动器锁定)。免除SQL数据库。释放的情况没有问题。为了更新系统,我们正在更新
驱动器映像。在此之前我们使用bcp从SQL 2012导出sql和其他数据,然后在重新映像后我们将sql数据导入到SQL 2014 db。代码如下。我们最初尝试运行它,关闭驱动器锁,看看
是否有所作为,但事实并非如此。

To further complicate matters we are and have been running this on a Windows 7 embedded system with File Base Write Filter (Drive lock) turned on. The SQL db is exempted. Same situation in release and no problems. In order to update the systems we are updating the drive image. Before doing this we export the sql and other data from SQL 2012 using bcp, then after reimaging we import the sql data into the SQL 2014 db. The code for that is below. We have tried running it initially with the drive lock off to see if that made a difference, but it didn't.

我不确定如何找出问题,更不用说修复它了(除了恢复旧版本)。任何好的想法都会很有意义iated。

I am not sure how to even find out the problem, much less fix it(except reverting to old versions). Any good ideas would be appreciated.

::从Sql Server 2012导出NxView的SQL数据

"%SQL%\\ \\bcp.exe" NxView.dbo.TxSummary out"%AppData%\ TxSummary.txt" -c -T -S。\ SQLEXPRESS

if%errorlevel%NEQ 0 set exit = 2

<跨度>"%SQL%\bcp.exe" NxView.dbo.TxDetail out"%AppData%\ TxDetail.txt" -c -T -S。\SQLEXPRESS

if%errorlevel%NEQ 0 set exit = 3

向SQL Server 2014导入数据

::清除现有数据库没有这个-E必须在bcp导入中用于处理软件管理的外键并可能导致损坏

"% SQL%\SQLCMD.EXE" -S。\SQLEXPRESS -i"%~dp0 \clear.sql"

if%errorlevel%NEQ 0 set exit = 6

::导入数据库

" %SQL%\bcp.exe" "%AppData%\ TxSummary.txt"中的NxView.dbo.TxSummary -c -T -S。\SQLEXPRESS

if%errorlevel%NEQ 0 set exit = 7

<跨度>"%SQL%\bcp.exe" "%AppData%\ TxDetail.txt"中的NxView.dbo.TxDetail -c -T -S。\SQLEXPRESS

if%errorlevel%NEQ 0 set exit = 8

del / Q"%AppData%\ TxSummary.txt"

if%errorlevel%NEQ 0 set exit = 9

del / Q"%AppData%\ TxDetail.txt"

if% errorlevel%NEQ 0 set exit = 10

推荐答案

更新:如果我运行它(基本上与上面相同的查询)  - " C:\Program Files \ Microsoft Microsoft SQL Server \110\Tools\Binn\SQLCMD.EXE" -S。\ SQLEXPRESS -Q" SELECT TOP 1 * FROM [NxView]。[dbo]。[TxSummary]" -o"C:\ TxSummary.txt" 
它很快完成。这绕过了实体框架,因此意味着问题在于使用EF。
UPDATE: If I run this(essentially the same query as above) - "C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE" -S .\SQLEXPRESS -Q "SELECT TOP 1 * FROM [NxView].[dbo].[TxSummary]" -o "C:\TxSummary.txt"  It finishes very quickly. This bypasses the Entity Framework, and would therefore imply the problem lies with the use of EF.


这篇关于从版本5.0.0升级到版本6.1.3时查询非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆