如何在中配置连接字符串ASP.Net MVC3 选项卡

发布于 2024-11-30 20:30:45 字数 259 浏览 4 评论 0原文

使用 VS2010 的 Net MVC3 应用程序,允许在选项卡中配置数据库连接字符串,如下所示

我的托管服务器如何不支持它并迫使我将连接字符串放入选项卡内,如下所示

我如何使用基于 MVC 3 实体框架代码优先模型的应用程序的 ConnectionString。是否可以将连接字符串放入选项卡中,如果可能的话,我如何在我的 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 use it in my ASP.Net MVC3 Entity Framework Code First Model ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖风昔人 2024-12-07 20:30:45

使用 connectionStrings 部分,而不是 appSettings

    <connectionStrings>
        <add name="MyApp" connectionString="DataSource=|DataDirectory|MyApp.sdf" providerName="System.Data.SqlServerCe.4.0" />
    </connectionString> 

这假设您的 DbContext 类也称为 MyApp。您需要更改上面连接字符串中的 MyApp 以匹配 DbContext 类的名称。

该连接字符串还假设您的项目中有一个 App_Data 文件夹。如果没有,您可以通过右键单击您的 Web 项目,选择“添加”、“Asp.Net 文件夹”,然后选择“App_Data”来添加它。

如果所有这些都设置正确,当您运行应用程序并点击使用 DbContext 的页面时,它将自动在 App_Data 文件夹中生成 sdf 文件。您还可以使用普通的 SQL Server 连接字符串,但 CE 是一种很好的方法,可以确保在您开始使用时一切都按照您希望的方式工作。

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.

独孤求败 2024-12-07 20:30:45

最后,经过大量的研发,我成功地在共享托管服务器上部署了我的 MVC3 应用程序,数据库连接正常工作,没有任何问题。我尝试在共享托管服务器上使用实体框架代码优先模型部署我的 MVC3 应用程序,但它没有不允许我这样做,因为我们没有共享托管服务器上的数据库创建和删除权限。我尝试了太多,它应该允许我使用实体框架代码优先托管我的应用程序,但由于共享托管数据库服务器的访问权限有限,我无法执行 id 操作。最后我需要找到一些替代方案,我尝试使用实体框架数据库优先模型部署我的 MVC3 应用程序。它将为您的模型类生成 edmx 文件,但您可以使用 ADO.Net DBContext 代码生成器的 T4 模板将其更新为 poco 类。请观看 Julie Lerman 的以下视频以了解更多信息。

http://msdn.microsoft.com/en-us/data/gg702905

如上面视频所示开发应用程序后,使用连接字符串中的托管服务器数据库值更改 web.config 设置,然后发布应用程序并将其上传到 FTP 服务器上。你发现它工作没有任何问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文