数据库和数据库架构突然超出同步

发布于 2025-02-07 05:50:24 字数 865 浏览 3 评论 0原文

我有一个非常奇怪的问题。

我有一个运行ASP.NET MVC应用程序查询SQL Server数据库的Web服务器。它们都是使用代码优先方法构建的。

很长一段时间以来,它一直没有问题,每当我需要一个新列时,我都将所需的类添加到了所讨论的模型中。然后,我已经运行add Migration'Migration_name',并且脚本已随着建议的更改而生成,并且在运行Update-Database之后,将更改应用于数据库。容易且总是在工作。

昨天,没有对数据库或模型进行任何更改(顺便说一下,甚至不更新网络服务器),它停止工作。

当Web应用程序试图访问数据库时,数据库会引发错误

system.data.sqlclient.sqlexception:“创建表格在数据库中拒绝的表格'master'

数据库的内容是完整的,我可以从Visual Studio中浏览它可以看到。

如果我运行add-mogration命令,则为整个数据库生成每个表,列,外键等脚本,好像数据库不包含在模型。

因此,似乎数据库不再与我的代码第一个模型同步了。我让我的IT部门将整个数据库复制到测试服务器,以尝试在不弄乱生产数据库的情况下测试错误,并尝试使用Update-Database命令运行“奇怪”迁移脚本后,我得到了同样的错误:

创建数据库中拒绝的表权限'Master'

,它表明我在尝试在迁移脚本中创建第一个表时它失败了。这并不奇怪,因为它已经存在于数据库中。但是发生了什么 - 我茫然!

那么,谁能告诉我可能在这里发生了,更重要的是,如何修复它?

一切顺利 TROELS

I have (I think) a very strange problem.

I have a web server running an ASP.NET MVC app querying a SQL Server database. It has all been constructed using code-first approach.

It has been working without problems for a long time, and whenever I have needed e.g. a new column in a table, I have added the needed class to the model in question. Then I have run Add-migration 'Migration_Name', and a script has been generating with the proposed changes, and after running update-database, the changes have been applied to the database. Easy and always working.

Yesterday, without making any changes to the database or the models (and by the way not even updating the web-server) it stopped working.

The database throws an error the moment the web-app tries to access the database

System.Data.SqlClient.SqlException: 'CREATE TABLE permission denied in database 'master'

The content of the database is intact I can see from browsing it from within Visual Studio.

If I run the add-migration command, a script is generated for every single table, column, foreign key etc for the entire database, as if the database did not contain a single one of the classes defined in the models.

So it seems that the database is not in sync with my code first models anymore. I got my IT department to copy the entire database to a test server to try to test what is wrong without messing up the production database, and after trying to run the "strange" migration script by using the update-database command, I get the same error:

CREATE TABLE permission denied in database 'master'

and it shows me that it fails when trying to create the first table in the migration script. This is not surprising, since it already exists in the database. But what is going on - I am at a loss!

So can anyone tell me might have happened here, and more importantly, how to fix it?

All the best
Troels

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文