How to configure Connection String in <appSettings> </appSettings> tab for ASP.Net MVC3
Net MVC3 application using VS2010 which allows to configure Database ConnectionString in tab as below
How ever my Hosting Server is not supporting it and force me to put connection string inside tab as below
How can i use ConnectionString of for MVC 3 Entity Framework Code First Model based applicaiton. Is it possible to put connection string inside tab and if its possible then how can i开发者_C百科 use it in my ASP.Net MVC3 Entity Framework Code First Model ?
Use the connectionStrings section, not appSettings
<connectionStrings>
<add name="MyApp" connectionString="DataSource=|DataDirectory|MyApp.sdf" providerName="System.Data.SqlServerCe.4.0" />
</connectionString>
This assumes your DbContext class is also called MyApp. You need to change MyApp in the connection string above to match the name of your DbContext class.
That connection string also assumes you have an App_Data folder in your project. If you do not, you can add it by right clicking your web project, choosing Add, Asp.Net Folder, then App_Data.
If all of that is set up properly, when you run your app and hit a page that uses the DbContext, it will automatically generate the sdf file in the App_Data folder. You can also use a normal SQL Server connection string, but CE is a nice way to make sure everything is working the way you would like it to when you're getting started.
Finaly after doing too much R&D i got success to deploy my MVC3 application on shared hosting server with Database connection properly working without any problem.I try to deploy my MVC3 application with Entity Framework Code First Model on shared hosting server but it don't allow me as we do not have database creation and drop permission on shared hosting server. I try too much it should allow me to host my application with Entity Framework Code First but i can't do id due to limited access permissions on shared hosting database server. Finaly i need to find some alternative and i try to deploy my MVC3 application with Entity Framework Database First Model. It will generate edmx file for your model class but you can update it to poco class using T4 template of ADO.Net DBContext Code Generator. Please watch Julie Lerman's below video to get more idea about it.
http://msdn.microsoft.com/en-us/data/gg702905
Once you develop your application as shown in above video, Change your web.config settings with your hosting server database value in Connection string and publish your application and upload it on your FTP Server. You found it work without any problem.
精彩评论