I've developed a software using VB.Net and SQL compact edition database. (.sdf file)
Now i want to add my .sdf file to setup file. I've search internet and create setup file.
when i install the software, it is created new folders in program files including my database file and exe file.
after double clicking exe file, it is open the software. but when using, it's shown a message "connection current state is closed". but when i run my vb project, it is working well.

other details.
=============

1) I create data base inside of <myProject>/bin/debug
2) I've created setup file using this method.
File menu --> add --> new project
Then, Setup and deployment -> Visual studio installer
After that I selected Setup project, then click OK.
3) I add database using this
Right click on setup file -> add -> file (In solution explorer window)
Then i selected my .sdf file.

this is my connection string

sqlcon = New SqlCeConnection("Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) + "\stuDB.sdf")

It is created only 3 files in Program files.
1. my exe
2. my sdf file
3. System.Data.SqlServerCe.dll file

Did you already tryed

sqlcon = New SqlCeConnection("Data Source=stuDB.sdf")

By default, to open the data base will use the standard search path, wich in the first place, is the path where the executable is placed.

Hope this helps

Data Source=stuDB.sdf is not working.
I tried this as well.
I hard coded database path like this.

sqlcon = New SqlCeConnection("Data Source=C:\stuDB.sdf") ' This path has the database

It also didn't work. (it is shown same error)
Then i copy my database to "D" partition and change conection string like this.
Data Source=D:\stuDB.sdf
It is working well. The problem is i cannot insert the database into my primary partition. So how to correct it?

Maybe, you have no write permission to the root of C:. Please check.

I would suggest to put the database in a folder other than the root.

Hope this helps.

So how to change write permission.
i have no idea how to change it...

1) You must logon with an acount belonging to the Administrators Group.
2) Select 'My Computer', and select Disc C:.
3) Click on the disc C: icon with the secondary button of the mouse, and select the Properties option.
4) There is a Security tab. Click on the Edit button, Accept to continue if the UAC asks for it, Click on the Add button, and enter the user name to be authorized. On the window, select the Allow Modify and check it. Then click OK and click OK.
5) Logon with the authorized user and verify the righ to write there.

Hope this helps

This article has been dead for over six months. Start a new discussion instead.