Permission denied for SQL Server CE on Win XP

天大地大妈咪最大 提交于 2019-12-11 09:18:36

问题


I am getting a "Permission denied" exception when I connect to a .sdf file.

I am using this connection string.

connection string="Data Source=|DataDirectory|\DB.sdf;Password='something';Mode = Read Only;Temp Path= Environment.GetFolderPath(Environment.SpecialFolder.Templates);Persist Security Info=True"" providerName="System.Data.EntityClient" />

This is work fine on Win 7 but when I run my app on Win XP it returns

Permission denied

exception

I tried different address for temp file but it still failed.all of this options are true

  1. The paths to the Database File exist on the xp machine
  2. I have permission to create a temporary file in the given directory
  3. I'm supplying the right password.

This problem happens just when data base connection string set to read only.i find some solution but i can't use them:

solution 1:

Here is the scoop on this. When we move a SDF file from XP to Vista, because of a change in the NLS Version we attempt to open the file in read-write mode to rewrite the indexes if any exist. This happens only on the first open on the move from XP to Vista. So a simple work around for you is to temporarily change the file to read-write mode open it on Vista and revert it back to read-only.

I can't use this solution because my application run from DVD.

solution 2:

having 3 sdf files, one for XP/Server 2003 and one for Vista/Server 2008/Win7 and one for win 8

This is also awful,because i don't have free space on application DVD to do this.

any one have a good idea to solve this problem.


回答1:


Copy the file to somewhere it can be written, and remove the Read Only property from the file. Connect to this file.

Environment.SpecialFolder can be called with SpecialFolder.LocalApplicationData to get a suitable location.

Path.GetTempPath might also be useful in this regard.




回答2:


You will need to either have 2 copies of the database file on the DVD, one for XP/Server 2003, and one for Vista and later. Or copy the database to a writable location when the app is first launched. Same issue applies to SQL Server Compact 4.0



来源:https://stackoverflow.com/questions/13064441/permission-denied-for-sql-server-ce-on-win-xp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!