I'm using EF 4 CTP 5 with an MVC 3 application, everything is working fine on my local machine, where EF 4 just create or drop the SQL CE whenever it needs to, since I have set the option to DropCreateDatabaseIfModelChanges
. But I'm now trying to deploy my mvc application to a hosting environment, where I've created the database already, but the database is empty. It seems like the code can't drop, and recreate the database on my hosting environment, how should I solve this problem?
Update:
Here's the connection string to SQLEXPRESS:
<add name="KennySax"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
开发者_StackOverflow中文版 database=KennySax;
AttachDBFilename=|DataDirectory|KennySax.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
Thanks.
One other option is to use Joachim Lykke Andersen's DontDropDbJustCreateTablesIfModelChanged database initializer
It deletes and re-creates the tables if the model changes
He even has a NuGet package for it
Usually your running application in hosting environment doesn't have permissinons to modify DB structure. So you can run your application in your own environment and use Management studio to connect to SQL CE. Then generate SQL script from your DB and manually run that script in hosted environment. I hope it works with SQL CE - it will definitely work with SQL Express.
Well I'm not sure what I did, seems like a restart of the machine solved the problem. I was able to have SQLEXPRESS create the database and run the script on the hosting server. Thanks.
精彩评论