简体   繁体   English

无法使用IIS访问我的网站中的SQL Server数据库

[英]Cannot access my SQL Server database in my website using IIS

My connection string is correct. 我的连接字符串正确。 It works when I debug and run from inside Visual Studio. 当我在Visual Studio中调试并运行时,它可以工作。

My problem is that I need to browse my site from the IIS to be able to access my website from any PC in my network. 我的问题是我需要从IIS浏览我的网站,以便能够从网络中的任何PC访问我的网站。

When I changed the application pool identity to localsystem , it worked. 当我将应用程序池标识更改为localsystem ,它起作用了。 I am worried that it won't work on any PC in my network, because I have no means to test it. 我担心它无法在我的网络中的任何PC上运行,因为我无法对其进行测试。

Can you confirm whether or not it would work? 您可以确认是否可行吗?

It sounds like you are connecting using windows authentication - ie: "Trusted Connection". 听起来您正在使用Windows身份验证进行连接-即:“受信任的连接”。

That is why you can connect using Visual Studio - you are using your credentials to connect. 这就是为什么您可以使用Visual Studio进行连接的原因-您正在使用凭据进行连接。

You need to run or impersonate IIS with an account that can connect to SQL Server, or allow IIS to impersonate the connected user, assuming they also have SQL server connection permissions. 您需要使用可以连接到SQL Server的帐户运行或模拟IIS,或者允许IIS模拟所连接的用户(假定他们也具有SQL Server连接权限)。

您需要像这样在连接字符串中添加用户名和密码

Data Source='server IP';Initial Catalog='database name';Persist Security Info=True;User ID='your user name';password='your password

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

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