繁体   English   中英

将连接字符串从SQL Server更改为Windows身份验证

[英]Changing connection string from SQL Server to windows authentication

我必须从SQL Server身份验证更改为Windows身份验证:

我的SQL Server身份验证字符串是:

 <add name="GCDataContext" 
      connectionString="Data Source=111.78.152.64;Initial Catalog=GC;User Id=sa;Password=xxxx;Trusted_Connection=False;Persist Security Info=True;MultipleActiveResultSets=True" 
      providerName="System.Data.SqlClient" />

改为(不工作)

 <add name="GCDataContext" 
      connectionString="Data Source=111.78.152.64;Initial Catalog=GC;Persist Security Info=True;Integrated Security=True;" 
      providerName="System.Data.SqlClient" />

有人可以帮我这个吗?

Integrated Security=True用于Windows身份验证,但未建立连接。

<add name="GCDataContext" 
      connectionString="Data Source=111.78.152.64;Initial Catalog=GC;Integrated Security=True" 
      providerName="System.Data.SqlClient" />  

这应该工作。

您只需要删除Persist Security Info=True
您也可以复制我的上述代码

默认情况下,ASP.NET应用程序不会模拟。 因此,当他们使用Windows身份验证连接到SQL Server时,他们使用Web应用程序的进程标识。 使用此方法,您的前端Web应用程序对其用户进行身份验证和授权,然后使用受信任的身份来访问数据库。 数据库信任应用程序的标识,并信任应用程序以正确地验证和授权呼叫者。

要使用Windows身份验证连接到SQL Server,请执行以下步骤:

步骤1.配置连接字符串。 与Windows身份验证一起使用的连接字符串必须包含Trusted_Connection = Yes属性或等效属性Integrated Security = SSPI,

步骤2.配置SQL Server安全性:您需要为应用程序的服务帐户创建SQL Server登录,并授予访问数据库的受限权限。 您的应用程序的服务帐户通常是网络服务帐户,它是用于在Windows Server 2003和IIS 6.0上运行ASP.NET应用程序池的默认帐户或自定义服务帐户。

为此,请执行以下操作 -

                 a).Create a SQL Server login for your application's account.
                 b).Map the login to a database user in the required database.
                 c). Provide appropriate permissions

<add name =“GCDataContext”connectionString =“Data Source = 111.78.152.64; Initial Catalog = GC; Integrated Security = True;” providerName =“System.Data.SqlClient”/>

删除:持久安全信息=真; 如果它无法连接验证数据库权限和权限。

暂无
暂无

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

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