Answered by:
Error running SqlCeEngine.Upgrade with SQL Compact 4.0 CTP

Question
-
Hi,
I am trying to run Upgrade with 4.0 CTP ADO.NET provider on a 3.5 database file, but get the following error:
Access to the database file is not allowed. [ File name = ]
Native Error: 25039
Visit my SQL Compact blog - http://erikej.blogspot.com - Please mark as answer, if this was it.Tuesday, July 13, 2010 6:14 PM
Answers
-
Update,
The bug has been fixed in SQLCE 4.0 RTM release.
Thanks, Tarun Ramsinghani Please mark this post as answers if it helps. “This post is provided "AS IS" with no warranties, and confers no rights”.- Marked as answer by ErikEJMVP Friday, April 15, 2011 6:22 AM
Friday, April 15, 2011 5:46 AM
All replies
-
Hi Erik,
Did you try running app in Administrator mode i.e out of UAC ?
Tarun Ramsinghani
Please mark this post as answers if it solves your problem.- Proposed as answer by Xiao-Min Tan – MSFT Wednesday, July 14, 2010 6:49 AM
- Unproposed as answer by ErikEJMVP Wednesday, July 14, 2010 6:53 AM
Wednesday, July 14, 2010 6:13 AM -
I did now, and it made my code work, thanks.
With 3.5 SP2, this was not required (and I find it to be a steep requirement, in order to do a file upgrade).
Is this change the desired behaviour / an expected requirement?
Visit my SQL Compact blog - http://erikej.blogspot.com - Please mark as answer, if this was it.Wednesday, July 14, 2010 6:25 AM -
I think this behaviour is not changed betweeen 3.5 and 4.0. Might be that the location of the sdf file had been different when you tried with 3.5 sp2. This happens in both versions when you try to access sdf file in "program files" or "windows" or "system drive" and application is running under UAC. Please let me know if this is not the case, we will have look at it.
Also can you try to access sdf file(or any other file) from same location using System.IO.File API's, while running your app under UAC (NonAdministrator Mode) and let me know the result.
Thanks,
Tarun Ramsinghani
Please mark this post as answers if it solves your problem.Wednesday, July 14, 2010 12:17 PM -
I think it may have changed.
The file is not in an UAC protected folder.
I can access the same file in the same location both with Compact 3.5 SP2 Upgrade API and with FileStream using a test app with 3.5 SP2.
In addition, I can access the file with FileStream in the Compact 4.0 test app.
The only API failing is the 4.0 Upgrade() API.
I can also open the test files in SSMS.
Both test apps are running under .NET 3.5 SP1.
This is my test code (must be modified to test with a 3.1 database file, of course)
public static class SqlCeUpgrade { public static void EnsureVersion40(this System.Data.SqlServerCe.SqlCeEngine engine, string filename) { SQLCEVersion fileversion = DetermineVersion(filename); if (fileversion == SQLCEVersion.SQLCE20) throw new ApplicationException("Unable to upgrade from 2.0 to 4.0"); if (SQLCEVersion.SQLCE40 > fileversion) { engine.Upgrade(); } } private enum SQLCEVersion { SQLCE20 = 0, SQLCE30 = 1, SQLCE35 = 2, SQLCE40 = 3 } private static SQLCEVersion DetermineVersion(string filename) { var versionDictionary = new Dictionary<int, SQLCEVersion> { { 0x73616261, SQLCEVersion.SQLCE20 }, { 0x002dd714, SQLCEVersion.SQLCE30}, { 0x00357b9d, SQLCEVersion.SQLCE35}, { 0x003d0900, SQLCEVersion.SQLCE40} }; int versionLONGWORD = 0; try { using (var fs = new FileStream(filename, FileMode.Open)) { fs.Seek(16, SeekOrigin.Begin); using (BinaryReader reader = new BinaryReader(fs)) { versionLONGWORD = reader.ReadInt32(); } } } catch { throw; } if (versionDictionary.ContainsKey(versionLONGWORD)) { return versionDictionary[versionLONGWORD]; } else { throw new ApplicationException("Unable to determine database file version"); } } }
Visit my SQL Compact blog - http://erikej.blogspot.com - Please mark as answer, if this was it.- Edited by ErikEJMVP Wednesday, July 14, 2010 12:29 PM added code sample
Wednesday, July 14, 2010 12:26 PM -
Code to call the above:
string filename = @"C:\Data\SQLCE\Northwind31.sdf"; var engine = new System.Data.SqlServerCe.SqlCeEngine("Data Source=" + filename); engine.EnsureVersion40(filename);
Visit my SQL Compact blog - http://erikej.blogspot.com - Please mark as answer, if this was it.- Proposed as answer by Michael_evosoft Wednesday, January 15, 2014 11:57 AM
Wednesday, July 14, 2010 12:31 PM -
Hi Erik,
It seems that it is currently not possible to do an in-place update. When you set a new filename in the Upgrade() method, everything works fine.
sqlCeEngine.Upgrade("Data Source=\"d:\\test\\test.sdf\"");
Is this a known issue with the CTP?
Thanks
Jus
Wednesday, July 14, 2010 8:03 PM -
Jus, as you can see from this thread, I am trying to convince the team that there is an issue.
Visit my SQL Compact blog - http://erikej.blogspot.com - Please mark as answer, if this was it.Thursday, July 15, 2010 6:13 AM -
Hi Erik,
I am unable to reproduce the mentioned situation on my side. Do you have a call stack when you get the exception? Call stack might help us to understand the situation better. Also is it happenening on Non-System Drive also ?
Thanks,
Tarun Ramsinghani
Please mark this post as answers if it solves your problem.Thursday, July 15, 2010 9:28 AM -
Jus, are you getting the same error as I do?
Visit my SQL Compact blog - http://erikej.blogspot.com - Please mark as answer, if this was it.Thursday, July 15, 2010 11:40 AM -
Stack trace:
at System.Data.SqlServerCe.SqlCeEngine.ProcessResults(IntPtr pError, Int32 hr)
at System.Data.SqlServerCe.SqlCeEngine.Repair(SEFIXOPTION option, String dstConnStr, RepairOption repairOption)
at ErikEJ.SqlCeScripting.SqlCeUpgrade.EnsureVersion40(SqlCeEngine engine, String filename) in C:\Data\SQLCE\ExpSqlCe\Generator\Helper.cs:line 340
System: Win 7 x64
App: 3.5 SP1 Console app, Any CPU build target
Also, I tested with files on a USB stick, same error.
Visit my SQL Compact blog - http://erikej.blogspot.com - Please mark as answer, if this was it.Thursday, July 15, 2010 12:26 PM -
OK Tarun, I did some more digging to help you nail down this issue:
Using procmon, I can see that the 4.0 dlls attempt to create a .tmp file in the root of the C: drive (which of course fails on Win 7).
In 3.5 SP2, the .tmp file is created in %temp% (a natural place).
Date & Time: 15-07-2010 15:34:32
Event Class: File System
Operation: CreateFile
Result: ACCESS DENIED
Path: C:\sqlC6B2.tmp
TID: 4464
Duration: 0.0000270
Desired Access: Generic Read
Disposition: Create
Options: Synchronous IO Non-Alert, Non-Directory File
Attributes: N
ShareMode: None
AllocationSize: 0Here is the stack dump from procmon:
0 fltmgr.sys fltmgr.sys + 0x2027 0xfffff8800108a027 C:\Windows\system32\drivers\fltmgr.sys
1 fltmgr.sys fltmgr.sys + 0x48ca 0xfffff8800108c8ca C:\Windows\system32\drivers\fltmgr.sys
2 fltmgr.sys fltmgr.sys + 0x222a3 0xfffff880010aa2a3 C:\Windows\system32\drivers\fltmgr.sys
3 ntoskrnl.exe ntoskrnl.exe + 0x374777 0xfffff80003188777 C:\Windows\system32\ntoskrnl.exe
4 ntoskrnl.exe ntoskrnl.exe + 0x36aa64 0xfffff8000317ea64 C:\Windows\system32\ntoskrnl.exe
5 ntoskrnl.exe ntoskrnl.exe + 0x36fb76 0xfffff80003183b76 C:\Windows\system32\ntoskrnl.exe
6 ntoskrnl.exe ntoskrnl.exe + 0x376887 0xfffff8000318a887 C:\Windows\system32\ntoskrnl.exe
7 ntoskrnl.exe ntoskrnl.exe + 0x380498 0xfffff80003194498 C:\Windows\system32\ntoskrnl.exe
8 ntoskrnl.exe ntoskrnl.exe + 0x6f853 0xfffff80002e83853 C:\Windows\system32\ntoskrnl.exe
9 ntdll.dll ntdll.dll + 0x502aa 0x77b402aa C:\Windows\System32\ntdll.dll
10 KernelBase.dll KernelBase.dll + 0x4d76 0x7fefdc24d76 C:\Windows\System32\KernelBase.dll
11 KernelBase.dll KernelBase.dll + 0x3b27c 0x7fefdc5b27c C:\Windows\System32\KernelBase.dll
12 sqlcecompact40.dll SeRebuild + 0x36b 0x6c2f93ef C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\sqlcecompact40.dll
13 sqlceme40.dll ME_Rebuild + 0x1c1 0x6c314491 C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\sqlceme40.dll
14 mscorwks.dll mscorwks.dll + 0x2ccd27 0x7fef6cccd27 C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
15 <unknown> 0x7ff001a6b43 0x7ff001a6b43Hope this helps
Visit my SQL Compact blog - http://erikej.blogspot.com - Please mark as answer, if this was it.Thursday, July 15, 2010 1:40 PM -
Thanks Erik, for helping us in finding the issue. I'll file a bug, and we will try to fix it in next release of 4.0.
Thanks,
Tarun Ramsinghani
Please mark this post as answers if it solves your problem.- Marked as answer by Xiao-Min Tan – MSFT Monday, July 19, 2010 2:49 AM
- Unmarked as answer by ErikEJMVP Friday, April 15, 2011 6:22 AM
Friday, July 16, 2010 7:01 AM -
Update,
The bug has been fixed in SQLCE 4.0 RTM release.
Thanks, Tarun Ramsinghani Please mark this post as answers if it helps. “This post is provided "AS IS" with no warranties, and confers no rights”.- Marked as answer by ErikEJMVP Friday, April 15, 2011 6:22 AM
Friday, April 15, 2011 5:46 AM