开发者

Using an SDF file (SQLCE database) with a custom extension as my WPF application's data file type

开发者 https://www.devze.com 2023-03-06 09:02 出处:网络
I\'m building an application in WPF (.NET 4) My application creates, opens and saves data files with a custom extension (I\'ll refer to them as .myapp files for clarity here). I\'m using an installer

I'm building an application in WPF (.NET 4)

My application creates, opens and saves data files with a custom extension (I'll refer to them as .myapp files for clarity here). I'm using an installer project to associate .myapp files with my installed program, and I've given them their own icon / actions / etc.)

A .myapp file is quite simply a SQLCE 3.5 database file with the extension changed from .sdf to .myapp.

It's working, but I'm looking for advice on whether this is a good way of doing things.

Part of me wonders whether I should make a .myapp file a wrapper file, which contains the SDF as well as some开发者_Go百科 metadata. I presume in doing it that way, that I would need to load the SDF into memory when I open the file, and then take responsibility for 'saving' it back to the file. My reasons for considering this option are:

  1. It would allow me to store additional metadata alongside the sdf, like intended application version, other quickly readable properties, etc.
  2. It would allow me open files in read-only mode (i.e. by not saving them back)
  3. It would (moreso) protect against somebody renaming the extension to .sdf and opening it with SQL Management Studio and messing around with the data.

Would this be a possible/better approach? By having the SDF loaded into memory, would I see performance benefits? Would there be any pitfalls to look out for?

Any other advice appreciated!


Using a custom document extension on your sdf files is an excellent idea. It would not work to wrap the sdf file in another file, and "load in memory", however, as you can only specify a file path in the SQL Server Compact connectionstring. The SQL Server Compact engine manages "loading in memory" for you and flushes to disk as required.

1: You could do this by storing the metatdata in a table/tables in the sdf file. 2: Opeining in read-only mode is a connection string option, so you can do that by changing the connection string. 3: You can specifiy a Password for the file (also in the connection string), and this will encrypt the database file.


One other benefit is you could do a simple encryption on the file. This would definitely make it more likely that no one would open the file directly and change data.

0

精彩评论

暂无评论...
验证码 换一张
取 消