首页 > 解决方案 > 如何在 Web 上使用 IIS 将 SQL 数据库连接到 Web 托管站点?

问题描述

我正在 asp.net 核心中构建一个测试 Web 应用程序,并且我从笔记本电脑托管了我的网站。一切似乎都很好,但是当我访问任何与数据库相关的页面时,页面只会加载一点,直到它给我一个错误并提示我进入开发人员模式以查看更多相关信息(我不能,因为该网站不在localhost 它在网络上)。我试图将我的连接字符串更改为它不起作用的不同迭代,该站点使用 IIS express 在本地工作。坦率地说,我不知道该怎么做文档似乎不存在,所以我很感激你的帮助。您可以在http://digital60.ddnsking.com/上测试该网站。

正在使用的连接字符串是:

"ConnectionStrings" : {
   "Default": "Data Source=DESKTOP-BULSITK\\SQLEXPRESS;Initial Catalog=TimsDinerDB;Integrated 
    Security=True;Connect 
Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
}

与数据库相关的页面是创建订单、列出食物、列出订单

如前所述,此设置在本地工作,但是当我在网络上托管我的网站时,它只是无法连接,在两种情况下都从笔记本电脑进行托管(操作系统或任何硬件都没有变化)。我不能在这里发布测试站点的所有代码,但如果有必要,我可以将所有代码放在 github 中,但我不认为这是问题所在。

标签: sqlasp.netdatabase

解决方案


好的,所以在我修复了很多小时后,我不确定是什么修复了它,但我相信这可能是我对连接字符串的更改,所以最终的连接字符串是:

"ConnectionStrings": {
"Default": "Server=.\\SQLExpress;Initial Catalog=TimsDinerDB;User Id=sa;Password=[Password];Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"}
}

you have to first activate the sa(server administrator) user from sql server for this one to work, and fill the password with the password you add to the sa user. I will try to see if it can be done with other users too. Other change I made was in security to add the IUSRS permissions to read write and modify but I am not certain if that was necessary.


推荐阅读