简体   繁体   English

ASP.NET MVC 应用程序部署问题

[英]Problem with ASP.NET MVC application deployment

I'm currently deploying my ASP.NET MVC5 project.我目前正在部署我的 ASP.NET MVC5 项目。 I already deployed project files, but I got some problems with, I guess, the database.我已经部署了项目文件,但我猜数据库有一些问题。 I did the following steps to deploy the database:我执行了以下步骤来部署数据库:

  1. Update-database -script in Visual Studio to get the SQL script of my local database (I developed it by code-first) Visual Studio 中的 update-database -script 以获取我本地数据库的 SQL 脚本(我通过代码优先开发它)

  2. Connect to the SQL Server database I created in my hosting panel.连接到我在托管面板中创建的 SQL 服务器数据库。

  3. Run the script I generated in 1.运行我在 1 中生成的脚本。

  4. Change the connection string in my web.config to this:将我的web.config中的连接字符串更改为:

     <connectionStrings> <add name="DefaultConnection" connectionString="Data Source=xxxxxx.xxxwebix.xx,2401;Initial Catalog=xxxxx;User ID=xxxxx;Password=xxxxx" providerName=".NET Framework Data Provider for SQL Server" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> </connectionStrings>

So basically I filled it in with the same credentials I had used to connect to the DB to run the script.所以基本上我用我用来连接到数据库以运行脚本的相同凭据填充它。

Unfortunately, I'm unable to register or login.不幸的是,我无法注册或登录。 I get an error我收到一个错误

An error occurred while processing your request.处理您的请求时发生错误。
500 (Internal Server Error) 500内部服务器错误)

in the console, which doesn't exactly say what's wrong.在控制台中,这并不能完全说明问题所在。 So basically, I know that the problem probably concerns the database, but I don't know what's wrong and how to get rid of it.所以基本上,我知道问题可能与数据库有关,但我不知道出了什么问题以及如何摆脱它。 This is my website (maybe it will help somehow): http://gymmanager.bartoszchodyla.pl.hostingasp.pl/这是我的网站(也许它会有所帮助): http://gymmanager.bartoszchodyla.pl.hostingasp.pl/

I'd be thankful for any help.我会很感激任何帮助。

EDIT I found the problem - providerName.编辑我发现了问题-providerName。 That's weird because I took it from the database properties after I connected to it in Visual Studio.这很奇怪,因为我在 Visual Studio 中连接到它后,从数据库属性中获取了它。 I changed it to default "System.Data.SqlClient" and it worked.我将其更改为默认的“System.Data.SqlClient”并且它有效。 Does someone knows why?有人知道为什么吗?

There are a lot of things that could be going on here.这里可能发生很多事情。 The fact it is throwing a 500 error means either some code is causing a major error and/or you do not have friendly errors turned on.它抛出 500 错误的事实意味着某些代码导致了重大错误和/或您没有打开友好错误。

There are some things you can do to figure out exactly where the issue is.您可以采取一些措施来准确找出问题所在。 In your console, make sure friendly errors are turned on, and you should get a bit more information.在您的控制台中,确保打开友好错误,您应该会获得更多信息。 You can also add try... catches to where you think the issue is and avoid the exception and write a message instead (this is fairly crude, but quick and easy).您还可以将 try... 捕获添加到您认为问题所在的位置,并避免异常并改为编写消息(这相当粗略,但又快又容易)。 Turning on tracing can also work, as long as you can actually spin up the application without the 500. You add trace statements before and after each routine and then go an examine the trace file.打开跟踪也可以工作,只要您实际上可以在没有 500 的情况下启动应用程序。您在每个例程之前和之后添加跟踪语句,然后 go 并检查跟踪文件。 The same can be done, in more crude fashion, by writing to a file.同样可以通过写入文件以更粗略的方式完成。 The use of this method is you can turn trace on and off at will.这种方法的使用是可以随意开启和关闭trace。

The fact you used code first is non-important if you are creating a SQL Script the correct way.如果您以正确的方式创建 SQL 脚本,那么您首先使用代码的事实并不重要。 When you run it, as long as it works (creates and possibly seeds?), you have the correct schema.当您运行它时,只要它有效(创建并可能是种子?),您就拥有正确的架构。

So, does the app throw the error up front or only when accessing data?那么,应用程序是预先抛出错误还是仅在访问数据时抛出错误? If the latter, you have a good place to start seeking out errors.如果是后者,您有一个很好的地方开始寻找错误。

BTW, you may be able to test locally against your providers database by changing your local connection strings.顺便说一句,您可以通过更改本地连接字符串来针对您的提供程序数据库进行本地测试。 It will depend on having certain ports open, which you might even be able to do if they are not for security reasons.这取决于是否打开某些端口,如果不是出于安全原因,您甚至可以这样做。 You can then debug the exception locally.然后,您可以在本地调试异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM