【问题标题】:Connection failed to SQL Server Express using user with SQL Server authentication使用具有 SQL Server 身份验证的用户连接到 SQL Server Express 失败
【发布时间】:2015-02-26 08:35:12
【问题描述】:

我在同一台机器上安装了 IIS 和 SQL Server Express。将网站部署到此环境后,我收到此错误:

无法打开登录请求的数据库“MyDB”。登录失败。 用户 'IIS APPPOOL\USER' 登录失败。

这是我设置 SQL Server 用户的连接字符串

<connectionStrings>
    <add name="myCS1" 
         connectionString="data source=172.20.3.20\SQLEXPRESS;initial catalog=MyDB;user id=SomeUser;password=SomeUser###;integrated security=True;MultipleActiveResultSets=True;" 
         providerName="System.Data.SqlClient" />
    <add name="myCS2" 
         connectionString="metadata=res://*/CLModel.csdl|res://*/CLModel.ssdl|res://*/CLModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=172.20.3.20\SQLEXPRESS;initial catalog=myDB;persist security info=True;user id=SomeUser;password=SomeUser###;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
         providerName="System.Data.EntityClient" />
</connectionStrings>

我想使用 SQL Server 用户连接到数据库,而不是 AppPool 用户。

我指定了登录名和密码,但似乎没有考虑此信息,并且在错误消息中我仍然看到 IIS 用户但看不到 sql。

我错过了什么?

【问题讨论】:

    标签: asp.net sql-server iis database-connection connection-string


    【解决方案1】:

    好吧,你指定 both - 明确的用户 ID 和密码,和 Integrated Security=True - 在你的myCS1 连接字符串中:

    data source=172.20.3.20\SQLEXPRESS;initial catalog=MyDB;
      user id=SomeUser;password=SomeUser###;integrated security=True;  
    

    在这种情况下,集成安全性胜过您的用户 - 您需要仅指定用户 ID 和密码并摆脱集成安全性 - 所以使用这个:

    <connectionStrings>
        <add name="myCS1" 
             connectionString="data source=172.20.3.20\SQLEXPRESS;initial catalog=MyDB;user id=SomeUser;password=SomeUser###;MultipleActiveResultSets=True;" 
             providerName="System.Data.SqlClient" />
        <add name="myCS2" 
             connectionString="metadata=res://*/CLModel.csdl|res://*/CLModel.ssdl|res://*/CLModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=172.20.3.20\SQLEXPRESS;initial catalog=myDB;persist security info=True;user id=SomeUser;password=SomeUser###;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
             providerName="System.Data.EntityClient" />
    </connectionStrings>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-07
      • 2011-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多