开发者

SQLite: Database connection to a resource-file?

i'm creating a dll which needs to connect to a database file using SQLite. Unfortunately, since my dll is used as an Excel AddIn, I don't really have a chance to figure out the path of where my dll is (Application references the Excel installation folder, all the Reflection.Assembly stuff is linked to either the Windows\GAC folder or something else). So long story short, I can't just put my SQLite file into my .dll-folder because it won't be found there when just using the connection string with a relative path, e.g. "Data Source=myfile.SQLite", and I can't figure out the full path to my original dll either due开发者_运维知识库 to the dll being used as an Excel AddIn.

My idea was to add the SQLite file to my project's resources, but I don't know how I could connect to a project resource with a regular SQLite connection string..is that even possible? If it's not, any other ideas how I could solve that?

Thanks!


There a number of less-than-ideal solutions:

1) Open/Create the sqlite db at a location determined by a convention, e.g. C:\Data. This is probably not ideal, but SQLite requires an actual data file, it cannot use e.g. a resource or isolated storage directly (There are other databases that do, see #3).

2) Use isolated storage, and copy the data from isolated storage to a temporary location at startup, and when the application shuts down (or on some other "persist event"), copy the file back to isolated storage.

3) Use a db that supports Isolated Storage, such as VistaDB. The obvious drawcback is the license cost (though small).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜