Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just been in the middle of doing this myself, one thing I would suggest is using SQL Compact Edition makes the process a lot easier, but if it's too late in the process at the moment then stick with the current database, However I do not know if the below method works with an MDF file.</p> <p>How are you deploying the application on the client machine? does the users machine have sql installed?</p> <p>The first thing you need to do is go to the properties of your MDF and ensure copy to output directory is set to copy if newer and build action is set to content.</p> <p>If you're using a setup project to install the application then you need to make sure in project, application properties, publish, application files that you're mdf is in the list and is set to Data File auto, required and include.</p> <p>and right click on the "Application Folder" in the installers file system, then add, project output, file contents</p> <p>Finally change the connection string in your code so that it reads</p> <pre><code>using ( SqlCeConnection sqlCon = new SqlCeConnection( @"Data Source=|DataDirectory|\App.sdf;Persist Security Info=False;" ) </code></pre> <p>or if you're not using compact Edition</p> <pre><code>using ( SqlConnection sqlCon = new SqlConnection( @"Data Source=|DataDirectory|\App.mdf;Persist Security Info=False;" ) </code></pre> <p>^using "DataDirectory" means that you don't care where the user puts the application, you will always get the right file</p> <p>before you run and change your database to compact, it doesnt support a lot of things a proper sql database will.</p> <p>After all this, you may still encounter errors with permissions and because its quite long winded I might have missed out a step so just comment if you need more?</p> <p><em>EDIT</em> If the user does not have either sql server or sql Compact, your easiest solution would be to require them to install SQL CE or there is a way of using DLLs that do the same thing but I couldn't get that to work</p> <p>the link for that is here <a href="http://msdn.microsoft.com/en-us/library/aa983326.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa983326.aspx</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload