简体   繁体   中英

How Do I make my Setup Project Include my Database (.sdf) file along with the winform application?

I have created a Winforms application in VS 10 (C#), with SQL Server Compact Edition 3.5 as a back end.

First I created a new setup project by following these steps.

But I got database file could not be found exception on installing application on client's machine.

Then I tried creating a setup project and included my database (.sdf) file in Application Folder and I got following exception:

Internal error: Cannot open the shared memory region.

I am getting the database file by following code :

SqlCeConnection con = new SqlCeConnection("DataSource=|DataDirectory|\\myDatabase.sdf");

And my DataDirectory is pointing to the path

string path = AppDomain.CurrentDomain.BaseDirectory;
AppDomain.CurrentDomain.SetData("DataDirectory", path);

Can anyone please help me including my database file?

Add the database file to your applications folder in your setup.

Then in your connection use

SqlCeConnection con = new SqlCeConnection("DataSource=myDatabase.sdf");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM