简体   繁体   English

无法在Appharbor连接到SQL Server

[英]Can't connect to SQL Server at Appharbor

I have created a simple ASP.NET MVC 5 application. 我创建了一个简单的ASP.NET MVC 5应用程序。

I'm trying to connect to the remote sql server provided by Appharbor - https://appharbor.com/addons/sqlserver 我试图连接到由Appharbor提供的远程SQL Server - https://appharbor.com/addons/sqlserver

So, visual part which does not use SQL requests works quite fine. 因此,不使用SQL请求的可视部分效果很好。 SQL requests throw errors like SQL请求抛出错误,例如

An error occurred while processing your request 处理您的请求时发生错误

I can't understand how to connect to the database. 我不明白如何连接到数据库。

I guess you deploy your code from github to apphb directly. 我猜您是将代码从github直接部署到apphb。 Then you have to config the sequencer on the apphb page. 然后,您必须在apphb页面上配置音序器。 In the plugin overview you can go to the configuration page for your sql server. 在插件概述中,您可以转到sql服务器的配置页面。 there create a entry with the same name as your connection string. 在那里创建一个与您的连接字符串同名的条目。 in your case "DefaultConnection". 在您的情况下为“ DefaultConnection”。

the way is: 方法是:

  1. click on your app on apphb 在apphb上点击您的应用
  2. under "Installed add-ons" click on SQL Server 在“已安装的附件”下,单击“ SQL Server”
  3. click "Go to SQL Server" 单击“转到SQL Server”
  4. click button "Edit database configuration" 单击按钮“编辑数据库配置”
  5. Add alias "DefaultConnection" (name from your connection string) 添加别名“ DefaultConnection”(连接字符串中的名称)
  6. click "save" 点击“保存”
  7. deploy your webpage again 再次部署您的网页

Next time you push to github and the hook triggers a build to apphb the server will automatically replace your local connection string with the apphb connection string. 下次您推送到github时,钩子触发构建到apphb的服务器将自动用apphb连接字符串替换您的本地连接字符串。

if you want to prepare your apphb database you have to let run the 'update-database' call from your visual studio. 如果要准备apphb数据库,则必须从Visual Studio中运行“ update-database”调用。 copy past the connection string from apphb to your web.config and run 'update-database' in your console to prepare the external DB with our schema. 将连接字符串从apphb复制到web.config,然后在控制台中运行“ update-database”,以使用我们的架构准备外部数据库。 But before you should add data within the Seed methode 但是在您应该在Seed方法中添加数据之前

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

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