sql server_SQL Server 身份验证标准连接:

更新时间:2017-03-28    来源:php与数据库    手机版     字体:

【www.bbyears.com--php与数据库】

SQL Server 身份验证标准连接:

Data Source = myServerAddress; Initial Catalog = myDataBase; User Id = myUsername; Password = myPassword;

server=.sqlexpress; database=testDB; uid=sa; pwd=123456

使用本地的SQL Server(localhost),如果想要使用远程服务器运行,应该在示例对象中把正确的服务器赋给Data Source 属性。此外,还必须指定所支持的两种身份验证方法(即Windows身份验证和SQL Server身份验证)中的其中一种。Windows身份验证使用Windows登录用户身份连接数据库教程,而SQL身份验证要求显式地指定SQL Server用户ID和密码。要想使用Windows身份验证,必须在连接字符串中包括 Integrated Security 属性:

Data Source=ServerName;Integrated Security=True;
 

 

默认情况下,Integrated Security 属性为 False ,这意味着将禁用Windows身份验证。如果没有显式地把这个属性的值设置为True,连接将使用SQL Server身份验证,因此,必须提供SQL Server用户ID和密码。Integrated Security属性还能识别的其他值只有SSPI(Security Support Provider Interface,安全性支持提供者接口)。在所有的Windows NT操作系统上,其中包括Windows NT 4.0、2000、XP,都支持值SSPI。它是使用Windows身份验证时可以使用的惟一接口,相当于把Integrated Security 属性值设置为True。

使用SQL Server的连接方式时,以本地服务器(LocalHost),数据库(testDB)为例,可以有以下一些连接方式

Data Source=LocalHost;Initial Catalog= testDB;Integrated Security=SSPI;Persist Security Info=False;Workstation Id=XXX;Packet Size=4096;
 

 

Server=LocalHost; Persist Security Info=False;Integrated Security=SSPI;Database= testDB;
Uid=sa;Pwd=sa;Initial Catalog=Northwind;Data Source=LocalHost;Connect Timeout=20;
 

 

在Windows身份验证模式中,SQL Server使用Windows的安全子系统对用户连接进行有效性验证。即使显示地指定用户ID和密码,SQL Server也不检查连接字符串中的用户ID和密码。因为只有Windows NT、2000、XP支持SSPI,因此如果正使用的是这些操作系统,则只能使用Windows集成的安全策略去连接SQL Server。不论使用哪一个操作系统,当使用SQL Server身份验证时,必须在连接字符串中指定用户ID和密码:

Server= ServerName,Data Source=DB;User ID=ID;Password=pwd

本文来源:http://www.bbyears.com/jiaocheng/31499.html

猜你感兴趣