【问题标题】:Using IIS App (Network Service - Windows Auth Only) - Not accessing SQL server使用 IIS 应用程序(网络服务 - 仅限 Windows 身份验证) - 不访问 SQL 服务器
【发布时间】:2015-08-13 14:07:02
【问题描述】:

当我在本地运行我的应用程序时,它可以连接到远程 SQL 服务器并很好地编辑数据库,但是,当使用 Windows Auth 将应用程序作为 NetworkService 添加到 IIS 应用程序池时。只是,每个sql请求都不会通过。

连接字符串:

connectionString="Data Source=ServerIP;Initial Catalog=DB_NAME;Persist Security Info=True;User ID=USER;Password=PASS" providerName="System.Data.SqlClient"

我已验证此 conn 字符串可从 localhost 访问和修改远程数据库。

当我发布时,页面会加载,但每当我尝试访问/编辑数据库时,我的代码都会失败。有什么想法吗?

【问题讨论】:

    标签: c# sql asp.net sql-server iis


    【解决方案1】:

    好的,我自己解决了。问题是当我从我使用的网络配置中获取连接字符串时:

    WebConfigurationManager.OpenWebConfiguration("~");
    

    当我需要将其更改为:

    WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多