EntityFramework: Reading SDF file from ProgramData folder?
I am developing a WPF/Entity Framework 4 app that use开发者_Python百科s SQL Compact 4.0 as its data store. I tried storing the database (SDF) file in a c:\ProgramData\MyCompany\MyApp\
folder. When my app tries to open the data store, I get the following exception: "The underlying provider failed on Open." The file opens fine if it is stored in a user folder.
I think the exception is thrown for security reasons--I suspect Windows, .NET, EF, or SQL Compact won't let me store an SDF file to the c:\ProgramData
folder. Is that correct? If so, I am puzzled, since that is typically where my apps store text logs. If I can log to the folder, why can't I put an SDF file there?
If I can't store to c:\ProgramData
, where should the file be stored, so that the same file is accessible to multiple users on a machine? Thanks for your help.
In your connection string, do you reference the database location with absolute path or relative one ?
If you use a relative path reference and your app is not run from "c:\ProgramData\MyCompany\MyApp\", that may be the problem as the app will always try to find your database file in its running folder.
Let me know if that helps.
Riana
I think you need to modify the access control list for the MyApp folder to Users RW
精彩评论