EF Code First 不适用于部署托管

发布于 2024-12-25 20:20:30 字数 216 浏览 3 评论 0原文

我有一个使用 MVC 和 Code First 来实现持久性的应用程序。

在我的开发中一切正常,但是当我上传到服务器时,它不起作用。

在任何地方,我尝试创建数据库,但它让我返回以下错误:数据库“master”中的创建数据库权限被拒绝。

我唯一做的就是重写 OnModelCreating 方法来映射我的应用程序。

有人有这个错误吗?

谢谢

I've an application using MVC and Code First for persistence.

Everything works fine in my development, but when I'm uploading to server, it doesnt work.

In any place i try to create a database, but it keeps me returning the following error: CREATE DATABASE permission denied in database 'master'.

The only thing that i do is override the OnModelCreating method just to map my app.

Anyone has this error?

Thanks

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

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

发布评论

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

评论(2

过潦 2025-01-01 20:20:30

有关演示如何发布 Code First 数据库并防止 Code First 尝试在生产中重新创建数据库的教程系列,请参阅
http://www.asp.net/mvc/tutorials/deployment -到托管提供商
本系列的第三篇教程展示了如何设置 Web.config 文件。第二个展示了如何部署(如果您使用的是 SQL Server Compact),第十个展示了如何部署到完整的 SQL Server。

For a tutorial series that shows how to publish your Code First database and prevent Code First from trying to re-create the database in production, see
http://www.asp.net/mvc/tutorials/deployment-to-a-hosting-provider
The third tutorial in the series shows how to set up the Web.config file. The second shows how to deploy if you are using SQL Server Compact, the tenth shows how to deploy to full SQL Server.

吃兔兔 2025-01-01 20:20:30

您需要将数据库发布给托管提供商。 Visual Studio 有一个简单的方法可以做到这一点。在服务器资源管理器选项卡中,您可以导航到数据库,右键单击并选择发布到提供商。通过这样做,您不仅可以导出数据库的方案,还可以导出所有数据、存储过程、视图等。

您将需要调整代码,以便不再尝试在代码上创建数据库跑步。通常,此方法用于开发,如果您要转移到托管公司,则您将不再处于开发状态。更改可能位于您的 global.asax、解决方案的 dbcontext 以及您修改它以创建数据库方案的任何其他位置。

希望这对您有所帮助,祝您的项目好运。

You'll need to publish your database out to your hosting provider. Visual Studio has an easy way of doing this. In the server explorer tab, you can navigate to your database, right click and choose publish to provider. By doing this, you will not only export the scheme of your database, but you can also export out all data, stored procs, views etc.

You will need to adjust your code so that you are no longer trying to create a database on code run. Typically this approach is used for development, and you are no longer in development if you're moving to a hosting company. The changes may be in your global.asax, the dbcontext of your solution and any other place where you modified it to create the scheme for the database.

Hope this helps you some, and good luck on your project.

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