1

I'm using a SQL Server CE .sdf database file and I configure this database in the app.config using this <connectionStrings> tag:

<connectionStrings>
    <add name="ReviewsDBConnection" 
         connectionString="data source=&quot;E:\GoogleDrive\bin\Debug\Data\ReviewsDB.sdf&quot;;password=123" 
         providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>

But whenever I move my project (the whole solution) to another PC, I get an error which says the ReviewsDB.sdf file path is not correct.

What should I write for data source that won't need to be changed when I move the solution to another PC? I'm using Telerik Open Access to get access to database.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Saman
  • 439
  • 7
  • 16

1 Answers1

2

As far as I understand you, you need to set relative path to the database in the connection string. If this is the case, with Telerik Data Access and SQL Server CE you can achieve it like this:

  1. Include the .sdf file in the data access layer project.
  2. Set the Copy to Output Directory property of the .sdf file to Copy always.
  3. Provide the connection string like this:

    <connectionStrings>
      <add name="ReviewsDBConnection" 
           connectionString="data source=|DataDirectory|\ReviewsDB.sdf;password=123" 
           providerName="System.Data.SqlServerCe.4.0" />
    </connectionStrings>
    
  4. Run the app for a test.

  • Would you please let me know how I can set the Copy to Output Directory property of the .sdf file to Copy always? Because I'm using visual studio 2013 and because it doesn't support sql compact edition, I've installed Sql server compact/SQLite and I can't find such a property in it. – Saman Feb 26 '15 at 14:52
  • 1
    Copy to Output Directory is a property of the .sdf file in the Properties window of Visual Studio. When you include the file in your project, select it, and press F4, Properties window will open for it. There you can choose the appropriate value. [This screencast](http://screencast.com/t/AgWjXXn4tFBS) will provide with an example. – Doroteya Agayna Mar 02 '15 at 10:43