天极Yesky
  • 笔记本电脑
    笔记本
  • 台式电脑
    台式机
  • 手机
    手机
  • 电脑硬件DIY
    DIY硬件
  • CPU
    主板
    音箱
  • 硬盘
    显卡
    键鼠
  • 内存光驱
    显示器
    机箱电源

  • 数码相机DC
    数码相机
  • MP3播放器
    MP3/MP4
  • 数码摄像机DV
    摄像机
  • 电脑外设
    外设
  • 网络
    网络
  • 服务器
    服务器
  • 数字家庭
    数字家庭
  • 群乐
    群乐
  • 产品报价 行情 经销商 渠道 评测 | 软件 设计 网页 开发 安全 论坛 E时代 游戏 图片 壁纸 下载 网摘 博客 索尼专区 Vista 科技奥运
    天极网
    理解SQL Server 2000的信任连接(Trusted connection)
    作者:
    出处: IT.ICXO.COM
    责任编辑: 丁一凡
    [ 2005-01-14 17:59 ]


     

    我在用OLEDB方式连接SQL Server时, 用到连接字: provider=SQLOLEDB.1;data source=localhost;initial catalog=WroxBooks; Trusted_Connection=yes; User ID=sa;Password=;
    调用后一直无法正常连接。


    ASP.NET错误描述:
    * Error while accessing data.
    用户 CXYASPNET 登录失败。


    ASP错误描述:
    Microsoft OLE DB Provider for SQL Server (0x80040E4D)
    用户 CXYIUSR_CXY 登录失败。


    已确信所连接的数据源,帐号和口令都是正确的,根据出错描述,怎么连接会用


    CXYASPNET或CXYIUSR_CXY登录?(我已明确指定User ID=sa;Password=;),经过多


    次试验,最后将连接字中的Trusted_Connection=yes;删除,连接成功!


    如果明白SQL Server登录验证的原理, 就可以知道Trusted Connection的含义。
    在SQL Server Architecture(SQL Server架构)登录篇中有关于Authenticating Logins(登录验证)的讲述, 摘录如下:


    ......

     

    SQL Server 2000 uses two types of authentication: Windows Authentication

     

    and SQL Server Authentication.

     

    ......

     

    When using Windows Authentication, you do not have to specify a login ID

     

    or password when you connect to SQL Server 2000. Your access to SQL

     

    Server 2000 is controlled by your Windows NT or Windows 2000 account or

     

    group, which is authenticated when you log on to the Windows operating

     

    system on the client.

     

    When you connect, the SQL Server 2000 client software requests a Windows

     

    trusted connection to SQL Server 2000. Windows does not open a trusted

     

    connection unless the client has logged on successfully using a valid

     

    Windows account. The properties of a trusted connection include the

     

    Windows NT and Windows 2000 group and user accounts of the client that

     

    opened the connection. SQL Server 2000 gets the user account information

     

    from the trusted connection properties and matches them against the

     

    Windows accounts defined as valid SQL Server 2000 logins. If SQL Server

     

    2000 finds a match, it accepts the connection. When you connect to SQL

     

    Server 2000 using Windows 2000 Authentication, your identification is

     

    your Windows NT or Windows 2000 group or user account.

     

    SQL Server 2000采用两种不同的验证方式:Windows验证和SQL Server 2000验证


    用Windows验证连接时,不必指定一个用户ID及口令,连接验证使用Windows NT或2000的组帐号(group account)。
    要知道:SQL Server 2000 在连接验证之前,用户先用Windows NT或2000的组帐号在客户端成功登录至SQL Server 2000服务器,方能建立一个信任连接(Trusted connection),SQL Server从信任连接属性中获取用户的帐号信息,将其与Windows已定义的帐号信息匹配和分析,如果正确就连接成功,并将此Windows帐号作为连接至SQL Server 2000的用户ID。


    上文中的连接字中包含有:Trusted_Connection=yes;
    这就意味着连接将采用信任连接方式,但由于连接前没有用Windows组帐号(在ASP环境中是访问IIS服务帐号IUSR_计算机名,在ASP.NET环境中帐号是ASPNET)登录至SQL Server 2000服务器, 也就是说没有建立一个信任连接(Trusted connection),当然,SQL Server 2000连接也不能够成功。


    将Trusted_Connection=yes;删除或改为Trusted_Connection=no;
    这将不采用信任连接方式(也即不采用Windows验证方式),而改由SQL Server 2000验证方式,即在连接字中指定:User ID=user name;Password=user password;
    SQL Server 2000会将此用户ID和口令进行验证连接,而与Windows帐号无关。


    关于SQL Server 2000上述两种验证方式的设置(连接验证采用Windows和SQL Server验证,还是仅采用Windows验证),可以启动SQL Server 2000企业管理器,然后在安全性配置中设置。

    笔名:
    请您注意:

     遵守国家有关法律、法规,尊重网上道德,承担一切因您的行为而直接或间接引起的法律责任。

     天极网拥有管理笔名和留言的一切权利。
    相关内容