1.连接数据库
[C#]
SqlConnection nwindConn = new SqlConnection("Data Source=localhost; Integrated Security=SSPI;Initial Catalog=northwind");
nwindConn.Open();
配置 Web.config 文件
在应用程序配置文件 (Web.config) 中,您可以建立应用程序使用的身份验证模式,并建立应用程序将模拟用户凭据(即该应用程序将以这名用户的身份运行)的模式?
配置 Web.config 以允许 Windows 集成安全性
打开应用程序的 Web.config 文件并向其添加以下元素:
<authentication mode="Windows" />
<identity impersonate="true"/>
<authentication> 元素可能已经存在。
注意 Web.config 中的元素区分大小写。
创建连接字符串
在创建连接字符串以访问 SQL Server 时,您必须包含通知 SQL Server 您正在使用 Windows 集成安全性的属性。
为 Windows 集成安全性配置连接字符串
在 SQL Server 的任何连接字符串中,包含属性 Trusted_Connection=Yes 并移除用户名和密码属性。
下面显示的是一个为 Windows 集成安全性配置的典型连接字符串:
"workstation id=WebServer1;packet size=4096;
Trusted_Connection=Yes;data source=mySqlServers";
persist security info=False;initial catalog=northwind"
[C#]
SqlConnection nwindConn = new SqlConnection("Data Source=localhost; Integrated Security=SSPI;Initial Catalog=northwind");
nwindConn.Open();
配置 Web.config 文件
在应用程序配置文件 (Web.config) 中,您可以建立应用程序使用的身份验证模式,并建立应用程序将模拟用户凭据(即该应用程序将以这名用户的身份运行)的模式?
配置 Web.config 以允许 Windows 集成安全性
打开应用程序的 Web.config 文件并向其添加以下元素:
<authentication mode="Windows" />
<identity impersonate="true"/>
<authentication> 元素可能已经存在。
注意 Web.config 中的元素区分大小写。
创建连接字符串
在创建连接字符串以访问 SQL Server 时,您必须包含通知 SQL Server 您正在使用 Windows 集成安全性的属性。
为 Windows 集成安全性配置连接字符串
在 SQL Server 的任何连接字符串中,包含属性 Trusted_Connection=Yes 并移除用户名和密码属性。
下面显示的是一个为 Windows 集成安全性配置的典型连接字符串:
"workstation id=WebServer1;packet size=4096;
Trusted_Connection=Yes;data source=mySqlServers";
persist security info=False;initial catalog=northwind"