OPENROWSET失败了"无效的授权规范"

时间:2018-02-21 18:57:35

标签: sql-server sql-server-2008 openrowset sqloledb

我正在尝试在SQL Server 2008 SP1中使用OPENROWSET

SELECT *
FROM OPENROWSET(
      'SQLOLEDB', 
      'Data Source=hydrogen;User ID=scratch;Password=scratch;',
      'select * from users')
  • OLE DB提供程序SQLOLEDB
  • 连接字符串Data Source=hydrogen;User ID=scratch;Password=scratch;
  • 命令文字select * from users

查询失败,显示:

  

OLE DB提供程序" SQLNCLI10"对于链接服务器"(null)"返回消息"无效的授权规范"。

     

OLE DB提供程序" SQLNCLI10"对于链接服务器"(null)"返回消息"无效的连接字符串属性"。

     

Msg 7399,Level 16,State 1,Line 1
  OLE DB提供程序" SQLNCLI10"对于链接服务器"(null)"报告错误。身份验证失败。

     

Msg 7303,Level 16,State 1,Line 1   无法初始化OLE DB提供程序的数据源对象" SQLNCLI10"对于链接服务器"(null)"。

注意:服务器和凭据当然是正确的。

但我没有使用SQLNCLI10

令人困惑的是错误表明有人正在使用OLE DB提供程序 SQLNCLI11 (SQL Server Native Client 11.0)

  

OLE DB提供程序" SQLNCLI10"对于链接服务器"(null)"返回消息

那不是我正在使用的OLEDB提供商。

  • 我没有使用OLE DB提供程序:SQLNCLI10 (SQL Server Native Client 11.0)
  • 我正在使用OLE DB提供程序:SQLOLEDB (用于SQL Server的Microsoft OLE DB提供程序)

所以有些事情是非常错误的。

随机尝试

当然,我们可以尝试随机的东西:

  • 在连接字符串中指定提供程序

    SELECT *
    FROM OPENROWSET(
          'SQLOLEDB', 
          'Provider=SQLOLEDB;Data Source=hydrogen;User ID=scratch;Password=scratch;',
          'select * from users')
    
  • 尝试使用SQLNCLI10 OLE DB提供程序:

    SELECT *
    FROM OPENROWSET(
          'SQLNCLI10', 
          'Data Source=hydrogen;User ID=scratch;Password=scratch;',
          'select * from users')
    
  • 尝试使用SQLNCLI10 OLE DB提供程序:

    SELECT *
    FROM OPENROWSET(
          'SQLNCLI10', 
          'Data Source=hydrogen;User ID=scratch;Password=scratch;',
          'select * from users')
    
  • 尝试使用集成安全性

    SELECT *
    FROM OPENROWSET(
          'SQLOLEDB', 
          'Data Source=hydrogen;Integrated Security=SSPI;',
          'select * from users')
    

除了不工作之外,这些尝试都没有回答我的问题:

  

为什么身份验证失败?

更多调试

使用无效的提供商 - 来证明它忽略了我的提供商。

服务器似乎坚持使用"原生客户端" 。如果我请求无效的OLE DB Provder会发生什么 - 例如asdfasf

SELECT *
FROM OPENROWSET(
      'qqqqqq', 
      'Data Source=hydrogen;User ID=scratch;Password=scratch;',
      'select * from users')

Msg 7403, Level 16, State 1, Line 1
The OLE DB provider "qqqqqq" has not been registered.

那是有道理的。因此,只有有时忽略了我的提供商。

使用有效的非SQL Server提供程序

如果我使用不是 SQL Server的有效提供商,该怎么办?

SELECT *
FROM OPENROWSET(
      'Microsoft.Jet.OLEDB.4.0', 
      'Data Source=hydrogen;User ID=scratch;Password=scratch;',
      'select * from users')

OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" returned message "Could not find installable ISAM.".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".

这是有道理的;办公室尚未安装。

提供商 SQLNCLI11

的连接字符串属性

属性集DBPROPSET_DBINIT

| PropertyID | Description             | Type
|------------|-------------------------|---------|
|          7 | Integrated Security     | VT_BSTR |
|          9 | Password                | VT_BSTR |
|         11 | Persist Security Info   | VT_BOOL | 
|         12 | User ID                 | VT_BSTR |
|         59 | Data Source             | VT_BSTR |
|         60 | Window Handle           | VT_I4   |
|         64 | Prompt                  | VT_I2   |
|         66 | Connect Timeout         | VT_I4   |
|        186 | Locale Identifier       | VT_I4   |
|        160 | Extended Properties     | VT_BSTR |
|        200 | Asynchronous Processing | VT_I4   |
|        233 | Initial Catalog         | VT_BSTR |
|        248 | OLE DB Services         | VT_I4   |
|        284 | General Timeout         | VT_I4   |

属性集DBPROPSET_SQLSERVERDBINIT

| PropertyID | Description                             | Type    |
|------------|-----------------------------------------|---------|
|          4 | Current Language                        | VT_BSTR |
|          5 | Network Address                         | VT_BSTR |
|          6 | Network Library                         | VT_BSTR |
|          7 | Use Procedure for Prepare               | VT_I4   |
|          8 | Auto Translate                          | VT_BOOL |
|          9 | Packet Size                             | VT_I4   |
|         10 | Application Name                        | VT_BSTR |
|         11 | Workstation ID                          | VT_BSTR |
|         12 | Initial File Name                       | VT_BSTR |
|         13 | Use Encryption for Data                 | VT_BOOL |
|         14 | Replication server name connect option  | VT_BSTR |
|         15 | Tag with column collation when possible | VT_BOOL |
|         16 | MARS Connection                         | VT_BOOL |
|         18 | Failover Partner                        | VT_BSTR |
|         19 | Old Password                            | VT_BSTR |
|         20 | DataTypeCompatibility                   | VT_UI2  |
|         21 | Trust Server Certificate                | VT_BOOL |
|         22 | Server SPN                              | VT_BSTR |
|         23 | Failover Partner SPN                    | VT_BSTR |
|         24 | Application Intent                      | VT_BSTR |

SQLOLEDB和SQLNCLI11

支持的OLE DB属性的比较

物业集: DBPROPSET_DBINIT

| PropertyID | Description             | Type    |  SQLOLEDB |  SQLNCLI11 |
|------------|-------------------------|---------|-----------|------------|
| 7          | Integrated Security     | VT_BSTR |  Yes      |  Yes       |
| 9          | Password                | VT_BSTR |  Yes      |  Yes       |
| 11         | Persist Security Info   | VT_BOOL |  Yes      |  Yes       |
| 12         | User ID                 | VT_BSTR |  Yes      |  Yes       |
| 59         | Data Source             | VT_BSTR |  Yes      |  Yes       |
| 60         | Window Handle           | VT_I4   |  Yes      |  Yes       |
| 64         | Prompt                  | VT_I2   |  Yes      |  Yes       |
| 66         | Connect Timeout         | VT_I4   |  Yes      |  Yes       |
| 160        | Extended Properties     | VT_BSTR |  Yes      |  Yes       |
| 186        | Locale Identifier       | VT_I4   |  Yes      |  Yes       |
| 200        | Asynchronous Processing | VT_I4   |           |  Yes       |
| 233        | Initial Catalog         | VT_BSTR |  Yes      |  Yes       |
| 248        | OLE DB Services         | VT_I4   |  Yes      |  Yes       |
| 284        | General Timeout         | VT_I4   |  Yes      |  Yes       |

物业集: DBPROPSET_SQLSERVERDBINIT

| PropertyID | Description                             | Type    |  SQLOLEDB | SQLNCLI11 |
|------------|-----------------------------------------|---------|-----------|-----------|
| 4          | Current Language                        | VT_BSTR |  Yes      | Yes       |
| 5          | Network Address                         | VT_BSTR |  Yes      | Yes       |
| 6          | Network Library                         | VT_BSTR |  Yes      | Yes       |
| 7          | Use Procedure for Prepare               | VT_I4   |  Yes      | Yes       |
| 8          | Auto Translate                          | VT_BOOL |  Yes      | Yes       |
| 9          | Packet Size                             | VT_I4   |  Yes      | Yes       |
| 10         | Application Name                        | VT_BSTR |  Yes      | Yes       |
| 11         | Workstation ID                          | VT_BSTR |  Yes      | Yes       |
| 12         | Initial File Name                       | VT_BSTR |  Yes      | Yes       |
| 13         | Use Encryption for Data                 | VT_BOOL |  Yes      | Yes       |
| 14         | Replication server name connect option  | VT_BSTR |  Yes      | Yes       |
| 15         | Tag with column collation when possible | VT_BOOL |  Yes      | Yes       |
| 16         | MARS Connection                         | VT_BOOL |           | Yes       |
| 18         | Failover Partner                        | VT_BSTR |           | Yes       |
| 19         | Old Password                            | VT_BSTR |           | Yes       |
| 20         | DataTypeCompatibility                   | VT_UI2  |           | Yes       |
| 21         | Trust Server Certificate                | VT_BOOL |           | Yes       |
| 22         | Server SPN                              | VT_BSTR |           | Yes       |
| 23         | Failover Partner SPN                    | VT_BSTR |           | Yes       |
| 24         | Application Intent                      | VT_BSTR |           | Yes       |

1 个答案:

答案 0 :(得分:1)

如果清除连接字符串中的空格,它应该可以工作,

SELECT a.*  
FROM OPENROWSET('SQLNCLI', 'Server=SQLOLEDB;Database=hydrogen;UID=scratch;PWD=scratch',  
     'SELECT * 
      FROM Users') AS a;