SQL Server CE在某些计算机上非常慢

时间:2022-12-08 09:32:26

I've built an app that uses SQL Server CE 4.0 by default, but can also use a separate SQL Server (SQL Server Express).

我已经构建了一个应用程序,它默认使用SQL Server CE 4.0,但也可以使用单独的SQL Server (SQL Server Express)。

I've deployed it to about 10 computers around the office and it works fine except on 2 of them: the VP and a QA guy, of course :-/

我已经把它部署到办公室里的大约10台电脑上,它工作得很好,除了两个:副总裁和一个QA,当然是:-/

On these computers, the database accesses are taking around 30 seconds each! If I install SQL Server Express 2008 R2, and tell my app to use it instead, then it runs very fast.

在这些计算机上,数据库访问每台大约需要30秒!如果我安装SQL Server Express 2008 R2,并让我的应用程序使用它,那么它运行得非常快。

  • Both problem machines are WinXP SP3, but most of the working PCs are XP also.
  • 这两款问题机都是WinXP SP3,但大多数正常运行的pc机也是XP。
  • I'm using C#.NET 4.0 App uses private deployment of SQL Server CE via ClickOnce.
  • 我使用c#。NET 4.0应用通过ClickOnce私有部署SQL Server CE。
  • I'm using DbProviderFactory to allow access to both SQL Server Express or SQL Server CE with the same query text (or data adapters).
  • 我使用DbProviderFactory允许使用相同的查询文本(或数据适配器)访问SQL Server Express或SQL Server CE。
  • Most of the queries are simple. A few use DataAdapter
  • 大多数查询都很简单。一些使用DataAdapter
  • Almost all of the queries eventually return data, but I saw one in my log file that returned empty, without an error/exception, but should have had about 20-40 rows and about 80 columns.
  • 几乎所有查询最终都会返回数据,但我在日志文件中看到一个查询返回为空,没有错误/异常,但应该有大约20-40行和大约80列。
  • For every query, I create, open and close the connection. I am unclear if this is required/recommended/not-recommended with SQL Server CE.
  • 对于每个查询,我创建、打开和关闭连接。我不清楚SQL Server CE是否需要/建议/不建议这样做。

I can't understand why this app works on most PCs, but not on these few.

我不明白为什么这个应用程序能在大多数个人电脑上运行,但不能理解这几个。

Any ideas are welcome.

任何想法都是受欢迎的。

Thanks!

谢谢!

2 个解决方案

#1


3  

The intermediate cause and workaround for this problem is with User access to .NET cryptography files used by a password-protected database. The problem was solved by changing the permissions on the folder.

这个问题的中间原因和解决方法是用户访问密码保护数据库使用的。net密码文件。通过更改文件夹上的权限解决了这个问题。

You can open command prompt with Run-As Admin and issue this command (Win XP)

您可以使用Run-As Admin打开命令提示符并发出此命令(Win XP)

 cacls.exe "C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys" /E /G Everyone:R

I also added this comment to my code near the SQLCE connection string code:

我还在SQLCE连接字符串代码附近的代码中添加了这条注释:

 /**************************************************************************************
 * To get rid of the slowdown on non-admin users you need to grant them read access to this folder:
 * C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys  (XP, 2003)
 * C:\Users\All Users\Microsoft\Crypto\RSA\MachineKeys  (Windows 7 or 2008)
 **************************************************************************************/

This issue is mentioned here: SqlCe opens slow under a limited user account in Windows XP

这里提到了这个问题:SqlCe在Windows XP中有限的用户帐户下打开速度很慢

And here: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/eb6a01a7-0bfd-41e3-b4c8-34581c5ccaa3/sql-compact-4-locks-up-30seconds-when-accessing-encrypted-database-on-windows-xp-when-running-in?forum=sqlce

这里:http://social.msdn.microsoft.com/forums/sqlserver/en - us/eb6a01a7 - 0 - bfd - 41 - e3 - b4c8 - 34581 - c5ccaa3/sql紧凑- 4 -锁- - 30秒-当访问加密-数据库- windows xp -当in?forum=sqlce——运行

Note: on the problem machine, the ...\MachineKeys folder was visible in WinExplorer, but the files couldn't actually be read. "Everyone" had "special" permissions that didn't allow "Read". I think .NET may have been installed by Domain admin, not local admin.

注意:在问题机器上,…\MachineKeys文件夹在WinExplorer中是可见的,但是文件实际上不能被读取。“每个人”都有不允许“阅读”的“特殊”权限。我认为。net可能是由域管理员而不是本地管理员安装的。

This is only a workaround. I still don't understand why the folder had weird permissions on a few machines but not the rest. I am deploying with ClickOnce, so I can't change the folder permissions automatically.

这只是一个变通办法。我仍然不明白为什么这个文件夹在一些机器上有奇怪的权限,而其他机器上没有。我正在使用ClickOnce进行部署,因此无法自动更改文件夹权限。

I have only seen this problem with XP, and other posts imply that this is just an XP problem, so hopefully I won't have to worry about it for long...

我只在XP中见过这个问题,其他文章暗示这只是一个XP问题,所以我希望我不会为此担心太久……

#2


2  

I had a similar problem with SQL Server CE. I found that installing the latest version from http://www.microsoft.com/en-us/download/details.aspx?id=17876 resolved the problem

我在SQL Server CE上遇到过类似的问题。我发现从http://www.microsoft.com/en-us/download/details.aspx?id = 17876解决了这一问题

I suspect that those machines already have an earlier version of SQL Server CE installed in the global assembly cache, and that the earlier version is being used instead of the locally deployed version.

我怀疑这些机器已经在全局程序集缓存中安装了较早版本的SQL Server CE,并且正在使用较早版本,而不是本地部署的版本。

Also, check the information from Lingzhi Sun in this post. Aparrently if the database is used on a different operating system from the one on which it was created, this can cause performance problems. This blog post may also be helpful.

同时,你也可以在这篇文章中查看一下孙灵芝的信息。如果数据库使用的操作系统与创建数据库的操作系统不同,这可能会导致性能问题。这篇博客文章也很有帮助。

#1


3  

The intermediate cause and workaround for this problem is with User access to .NET cryptography files used by a password-protected database. The problem was solved by changing the permissions on the folder.

这个问题的中间原因和解决方法是用户访问密码保护数据库使用的。net密码文件。通过更改文件夹上的权限解决了这个问题。

You can open command prompt with Run-As Admin and issue this command (Win XP)

您可以使用Run-As Admin打开命令提示符并发出此命令(Win XP)

 cacls.exe "C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys" /E /G Everyone:R

I also added this comment to my code near the SQLCE connection string code:

我还在SQLCE连接字符串代码附近的代码中添加了这条注释:

 /**************************************************************************************
 * To get rid of the slowdown on non-admin users you need to grant them read access to this folder:
 * C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys  (XP, 2003)
 * C:\Users\All Users\Microsoft\Crypto\RSA\MachineKeys  (Windows 7 or 2008)
 **************************************************************************************/

This issue is mentioned here: SqlCe opens slow under a limited user account in Windows XP

这里提到了这个问题:SqlCe在Windows XP中有限的用户帐户下打开速度很慢

And here: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/eb6a01a7-0bfd-41e3-b4c8-34581c5ccaa3/sql-compact-4-locks-up-30seconds-when-accessing-encrypted-database-on-windows-xp-when-running-in?forum=sqlce

这里:http://social.msdn.microsoft.com/forums/sqlserver/en - us/eb6a01a7 - 0 - bfd - 41 - e3 - b4c8 - 34581 - c5ccaa3/sql紧凑- 4 -锁- - 30秒-当访问加密-数据库- windows xp -当in?forum=sqlce——运行

Note: on the problem machine, the ...\MachineKeys folder was visible in WinExplorer, but the files couldn't actually be read. "Everyone" had "special" permissions that didn't allow "Read". I think .NET may have been installed by Domain admin, not local admin.

注意:在问题机器上,…\MachineKeys文件夹在WinExplorer中是可见的,但是文件实际上不能被读取。“每个人”都有不允许“阅读”的“特殊”权限。我认为。net可能是由域管理员而不是本地管理员安装的。

This is only a workaround. I still don't understand why the folder had weird permissions on a few machines but not the rest. I am deploying with ClickOnce, so I can't change the folder permissions automatically.

这只是一个变通办法。我仍然不明白为什么这个文件夹在一些机器上有奇怪的权限,而其他机器上没有。我正在使用ClickOnce进行部署,因此无法自动更改文件夹权限。

I have only seen this problem with XP, and other posts imply that this is just an XP problem, so hopefully I won't have to worry about it for long...

我只在XP中见过这个问题,其他文章暗示这只是一个XP问题,所以我希望我不会为此担心太久……

#2


2  

I had a similar problem with SQL Server CE. I found that installing the latest version from http://www.microsoft.com/en-us/download/details.aspx?id=17876 resolved the problem

我在SQL Server CE上遇到过类似的问题。我发现从http://www.microsoft.com/en-us/download/details.aspx?id = 17876解决了这一问题

I suspect that those machines already have an earlier version of SQL Server CE installed in the global assembly cache, and that the earlier version is being used instead of the locally deployed version.

我怀疑这些机器已经在全局程序集缓存中安装了较早版本的SQL Server CE,并且正在使用较早版本,而不是本地部署的版本。

Also, check the information from Lingzhi Sun in this post. Aparrently if the database is used on a different operating system from the one on which it was created, this can cause performance problems. This blog post may also be helpful.

同时,你也可以在这篇文章中查看一下孙灵芝的信息。如果数据库使用的操作系统与创建数据库的操作系统不同,这可能会导致性能问题。这篇博客文章也很有帮助。