gpt4 book ai didi

asp.net-mvc - 无法删除数据库,因为它当前正在使用MVC

转载 作者:行者123 更新时间:2023-12-03 12:00:34 26 4
gpt4 key购买 nike

我是使用MVC的新手,并且正在尝试使用初始化程序在应用程序首次启动时将数据初始化到我的数据库中。这是我在Global.asax.cs中得到的:

 System.Data.Entity.Database.SetInitializer(new MyAppInitializer());
MyAppContext db = new MyAppContext();
db.Database.Initialize(true);

在Web.config中,这是我的连接字符串:
<connectionStrings>
<add name="MyAppContext"
connectionString="data source= MyServer; Integrated Security=True; database=MyDatabase"
providerName="System.Data.SqlClient"/>

这是使用MS SQL 2008 R2。我的初始化器如下所示:
public class MyAppInitializer : DropCreateDatabaseAlways<MyAppContext>
{
protected override void Seed(MyAppContext context)
{
var organizations = new List<Organizations>
{
new Organizations { OrgName = "AT", OrgPhone = 5093333433, OrgOfficeLocation = "ITB", OrgPointOfContact = "Tony", OrgIsActive = 1 },
new Organizations { OrgName = "Libraries", OrgPhone = 5093331122, OrgOfficeLocation = "Holland-Terrell", OrgPointOfContact = "Herald", OrgIsActive = 1 }
};
organizations.ForEach(s => context.Organizations.Add(s));
context.SaveChanges();

我确保在SQL Server Management Studio中关闭了与服务器和数据库的连接,但是有多个人可以访问该数据库,尽管现在没有人可以使用它。如何获取它,以便可以在数据库中初始化此数据?谢谢!

编辑:我已经在服务器上创建了数据库,但是它是完全空的(没有表,过程等)。这会引起问题吗?

最佳答案

在SSMS中运行类似这样的内容...

USE master -- be sure that you're not on MYDB
ALTER DATABASE MYDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DROP DATABASE MYDB;

关于asp.net-mvc - 无法删除数据库,因为它当前正在使用MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17095472/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com