尝试使用Azure托管测试站点,但SQL数据库不会传输

时间:2023-01-02 07:22:39

I am a new web developer and am trying to host a test site with Azure test services.

我是一名新的Web开发人员,正在尝试使用Azure测试服务来托管测试站点。

I can see the test site(you can access this to test ) at: http://kencast20160830102548.azurewebsites.net/

我可以在http://kencast20160830102548.azurewebsites.net/看到测试站点(您可以访问此测试)

However, if you go to the Services -> Fazzt --> Equipment and Applications pages, I get this error:

但是,如果您转到服务 - > Fazzt - >设备和应用程序页面,我会收到此错误:

Error. An error occurred while processing your request. Development Mode Swapping to Development environment will display more detailed information about the error that occurred.

错误。处理您的请求时发生错误。开发模式交换到开发环境将显示有关发生的错误的更详细信息。

Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable toDevelopment, and restarting the application."

不应在已部署的应用程序中启用开发环境,因为它可能导致向最终用户显示异常的敏感信息。对于本地调试,可以通过将ASPNETCORE_ENVIRONMENT环境变量设置为Development并重新启动应用程序来启用开发环境。

These pages are relying on a SQL database, so I think this is where the problem is.

这些页面依赖于SQL数据库,所以我认为这就是问题所在。

I've been trying to follow along with the directions published here: https://docs.asp.net/en/latest/tutorials/publish-to-azure-webapp-using-vs.html

我一直在努力遵循这里发布的指示:https://docs.asp.net/en/latest/tutorials/publish-to-azure-webapp-using-vs.html

however I cannot find the "Configure SQL Database" pop-up box when logged into my Microsoft Azure account.

但登录到我的Microsoft Azure帐户时,我找不到“配置SQL数据库”弹出框。

The directions do not seem to go along with what exists in Azure.

这些指示似乎与Azure中存在的内容不符。

Update- 8/31/2016

更新 - 2016年8月31日

I have researched and learned a bit more: I have one project with two DBContexts.

我已经研究和学习了一点:我有一个项目有两个DBContexts。

When I publish to Azure, it publishes tables from ApplicationDBContext but not the tables from MyCompanyContext. I can verify using SQL Server Object Explorer. I can see my local connection strings in appsettings.json file for both ApplicationDB and MyCompanyDB. Here is the code from appsettings.json:

当我发布到Azure时,它从ApplicationDBContext发布表,但不发布MyCompanyContext中的表。我可以使用SQL Server对象资源管理器验证。我可以在appsettings.json文件中看到ApplicationDB和MyCompanyDB的本地连接字符串。以下是appsettings.json的代码:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-MyCompany-3097a012-5e00-4c25-ad83-2730b4d73b4b;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "Data": {
    "MyCompanyContext": {
      "ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=MyCompanyContext-f9de2588-77e8-41dd-abb3-84341610b31a;Trusted_Connection=True;MultipleActiveResultSets=true"
    }
  }

}

}

However, when I look at the "SQL Server Object Explorer" window, I see that the database hosted on Azure, mycompanydb.database.windows.net(SQL Server 11.0.9231 -mycompanydb, MyCompany_db) only has the tables from the "DefaultConnection" database, and nothing from "MyCompanyContext".

但是,当我查看“SQL Server对象资源管理器”窗口时,我看到Azure上托管的数据库mycompanydb.database.windows.net(SQL Server 11.0.9231 -mycompanydb,MyCompany_db)只有“DefaultConnection”中的表。 “数据库,而不是”MyCompanyContext“。

How do I get the tables from the second database (MYCompanyContext) to Azure?

如何将表从第二个数据库(MYCompanyContext)获取到Azure?

I have been studying this Stack Overflow response, but it uses Enable-Migration in the PMC. When I do that, I get an error that enable-migrations is obsolete.

我一直在研究这个Stack Overflow响应,但它在PMC中使用Enable-Migration。当我这样做时,我收到一个错误,启用 - 迁移已过时。

Locally, I have always done migrations with this: add-migrations -c MyCompanyContext

在本地,我总是用这个进行迁移:add-migrations -c MyCompanyContext

Any help you could give me would be greatly appreciated.

任何你能给我的帮助将不胜感激。

Thanks!

谢谢!

1 个解决方案

#1


1  

From the comments, I am guessing you need to ensure both your contexts are applied in the startup class like this

从评论中,我猜你需要确保你的上下文在这样的启动类中应用

  services.AddEntityFramework().AddSqlServer()
            .AddDbContext<MyCompanyContext>(options => options.UseSqlServer(Configuration.Get("Data:SQL")))
            .AddDbContext< ApplicationDBContext >(options => options.UseSqlServer(Configuration.Get("Data:SQL")));

the above assumes two things: 1) you have the connection string set up like this in your appsettings.json

上面假设了两件事:1)你在appsettings.json中设置了这样的连接字符串

"Data": {
"SQL": "Server=tcp:yourDbServer.database.windows.net,1433;Initial Catalog=yourDb;Persist Security Info=False;User ID=youId;Password=YourPswd;MultipleActiveResultSets=True;TrustServerCertificate=False;Connection Timeout=30;",
}

2) Both the contexts share the same Db, if not then substitute the appropriate connection string (make sure to have it matched to the way you have it in your appsettings.json) for the context like this sample:

2)两个上下文共享相同的Db,如果没有,那么替换相应的连接字符串(确保它与你在appsettings.json中的方式匹配)对于像这样的上下文:

.AddDbContext<MyCompanyContext>(options => options.UseSqlServer(Configuration.Get("Data:SQL2")));

#1


1  

From the comments, I am guessing you need to ensure both your contexts are applied in the startup class like this

从评论中,我猜你需要确保你的上下文在这样的启动类中应用

  services.AddEntityFramework().AddSqlServer()
            .AddDbContext<MyCompanyContext>(options => options.UseSqlServer(Configuration.Get("Data:SQL")))
            .AddDbContext< ApplicationDBContext >(options => options.UseSqlServer(Configuration.Get("Data:SQL")));

the above assumes two things: 1) you have the connection string set up like this in your appsettings.json

上面假设了两件事:1)你在appsettings.json中设置了这样的连接字符串

"Data": {
"SQL": "Server=tcp:yourDbServer.database.windows.net,1433;Initial Catalog=yourDb;Persist Security Info=False;User ID=youId;Password=YourPswd;MultipleActiveResultSets=True;TrustServerCertificate=False;Connection Timeout=30;",
}

2) Both the contexts share the same Db, if not then substitute the appropriate connection string (make sure to have it matched to the way you have it in your appsettings.json) for the context like this sample:

2)两个上下文共享相同的Db,如果没有,那么替换相应的连接字符串(确保它与你在appsettings.json中的方式匹配)对于像这样的上下文:

.AddDbContext<MyCompanyContext>(options => options.UseSqlServer(Configuration.Get("Data:SQL2")));