SQL SERVER 2012/2014 链接到 SQL SERVER 2000的各种坑

时间:2021-12-15 16:13:25

本文总结一下SQL SERVER 2012/2014链接到SQL SERVER 2000的各种坑,都是在实际应用中遇到的疑难杂症。可能会有人说怎么还在用SQL SERVER 2000,为什么不升级呢? 每个公司都会有一两个几乎快被人遗忘的系统,接手维护这些系统的人可能都不知换了多少批了。它们的命运注定慢慢消亡。然而偏偏却又生命力顽强,总还有一些人在使用着这些系统。所以就处在一种尴尬的境地: 升级吧,价值不大,可能再过一两年,这系统就要被其它系统替代了。而且项目经理也没有精力、人手耗费在这上面。最重要的是担心风险问题。因为接手维护的人对这些系统都不甚了解。如果贸然升级,可能风险很大。

1:SQL Server Native Client 11.0 does not support connections to SQL Server 2000 or earlier versions

自SQL Server 2012开始,已经不支持通过链接服务器链接到SQL Server 2000。主要是SQL SERVER 2012/2014安装的是SQL Server Native Client 11.0。而SQL Server Native Client 11.0 does not support connections to SQL Server 2000 or earlier versions。关于这个官方文档

已有说明,具体如下所示:

This topic discusses how various data-access components can be used with SQL Server Native Client.

Server Support

SQL Server Native Client 11.0 supports connections to SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, and Windows Azure SQL Database.

Supported Operating System Versions

The following table lists which operating systems support SQL Server Native Client.

SQL Server Native Client version

Supported operating systems

SQL Server Native Client (SQL Server 2005)

  • Microsoft Windows 2000 Service Pack 4 or later
  • Microsoft Windows Server 2003 or later
  • Microsoft Windows XP Service Pack 1 or later
  • Microsoft Windows Vista (requires SQL Server Service Pack 2, or later)
  • Microsoft Windows Server 2008 (requires SQL Server Service Pack 2, or later)

SQL Server Native Client 10.0 (SQL Server 2008)

  • Microsoft Windows Server 2003 Service Pack 2, or later
  • Microsoft Windows XP Service Pack 2, or later
  • Microsoft Windows Vista
  • Microsoft Windows Server 2008

SQL Server Native Client 10.5 (SQL Server 2008 R2)

  • Microsoft Windows Server 2003 Service Pack 2, or later
  • Microsoft Windows XP Service Pack 2 or later
  • Microsoft Windows Vista
  • Microsoft Windows Server 2008
  • Microsoft Windows 7

SQL Server Native Client 11.0 (SQL Server 2012)

  • Microsoft Windows Vista
  • Microsoft Windows Server 2008
  • Microsoft Windows 7
  • Microsoft Windows 8
  • Microsoft Windows Server 2012

此时需要安装SQL Server Native Client 10. 我在这篇文章SQL SERVER 2012链接到SQL SERVER 2000的问题解决案例里面介绍了如何安装SQL Server Native Client 10

 

2: 即使安装了SQL Server Native Client 10,依然不能使用下面常规的建立链接服务器的方法建立

EXEC master.dbo.sp_addlinkedserver @server = N'server_name', @srvproduct=N'SQL Server'

 

EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'server_name',@useself=N'False',@locallogin=NULL,@rmtuser=N'username',@rmtpassword='########'

 

GO

 

3:以下面方式建立链接服务器,能够成功创建链接服务器,测试链接也OK,似乎一切OK

EXEC master.dbo.sp_addlinkedserver @server = N'server_name', @srvproduct=N'SQLSERVER', @provider=N'SQLNCLI10', @provstr=N'DRIVER={SQL Server Native Client 10.0};SERVER=192.168.xxx.xxx;'

 

EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'server_name',@useself=N'False',@locallogin=NULL,@rmtuser=N'username',@rmtpassword='########'

 

GO

但是在调用链接服务器时,就会出现下面错误。

Msg 7399, Level 16, State 1, Line 1

The OLE DB provider "SQLNCLI10" for linked server "xxxxx" reported an error. Access denied.

Msg 7301, Level 16, State 2, Line 1

Cannot obtain the required interface ("IID_IDBCreateCommand") from OLE DB provider "SQLNCLI10" for linked server "xxxxx".

配置

4: OpenDataSource  SQL Server Native Client 11.0 does not support connections to SQL Server 2000

如果代码里面有使用OpenDataSource,那么就会报上面的错误。此时必须修改为链接服务器方式访问。

SQL SERVER 2012/2014正确链接到SQL SERVER 2000的方法,

EXEC master.dbo.sp_addlinkedserver @server = N'Server_Name', @srvproduct=N'sqlserver', @provider=N'MSDASQL', @provstr=N'DRIVER={SQL Server Native Client 10.0};SERVER=192.168.xxx.xxx;'

 

 

EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'Server_Name',@useself=N'False',@locallogin=NULL,@rmtuser=N'UserName',@rmtpassword='########'

 

GO

 

参考资料:

https://social.msdn.microsoft.com/Forums/en-US/7352802d-5294-45e1-999e-8749a38952eb/linked-server-sql-2012-to-2000-error-microsoft-distributed-transaction-coordinator-ms-dtc-has?forum=sqldatabaseengine

https://connect.microsoft.com/SQLServer/feedback/details/731869/using-sqlncli10-to-create-a-linked-server-to-sql-server-2000-causes-a-fault

https://msdn.microsoft.com/en-us/library/cc280356(v=SQL.110).aspx