Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use SQL Server CE Locally and SQL Server 2008 on Production Entity Framework Code First?

I am using EF Code first to generate my models. I have added SQL Server Compact Edition to my project and am using that as a DB locally.

I want to configure the DataContext so that when I push to Production (based on the machine name) it instead would pull from a connection string in the Web Config and use a SQL Server 2008 DB.

What is the easiest way to do this? Basically my question is at what point do I need to add the conditional so that when it is deployed it pulls in the connection string and just works.

Is this even a recommended approach?

like image 845
aherrick Avatar asked Dec 03 '25 06:12

aherrick


2 Answers

This discussion has one approach where you have multiple settings in the same config file. Here the suggestion is to use multiple config files, one for each environment or use MSBuild to produce select a config file.

using #IF DEBUG is another option but risky where a developer decides to test a release version and forgets they are running against a live system!

like image 159
IndigoDelta Avatar answered Dec 04 '25 20:12

IndigoDelta


My first thought is that you only need to deliver a different ConnectionString when you deploy your App.Config

Using different 'Solution Configurations' (Debug/Release/ etc.) there are possibilities to even automate this via with MSBuild.

like image 20
Jens H Avatar answered Dec 04 '25 21:12

Jens H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!