Question

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).

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 :-/

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.

  • Both problem machines are WinXP SP3, but most of the working PCs are XP also.
  • I'm using C#.NET 4.0 App uses private deployment of SQL Server CE via ClickOnce.
  • I'm using DbProviderFactory to allow access to both SQL Server Express or SQL Server CE with the same query text (or data adapters).
  • Most of the queries are simple. A few use 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.
  • For every query, I create, open and close the connection. I am unclear if this is required/recommended/not-recommended with SQL Server CE.

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

Any ideas are welcome.

Thanks!

Was it helpful?

Solution

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.

You can open command prompt with Run-As Admin and issue this command (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:

 /**************************************************************************************
 * 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

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

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.

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.

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...

OTHER TIPS

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

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top