SQL Server 2012版本的Microsoft.SqlServer.Types的几何UDT是否向后兼容SQL Server 2008? [英] Is the SQL Server 2012 version of Microsoft.SqlServer.Types' geometry UDT backward compatible with SQL Server 2008?

查看:173
本文介绍了SQL Server 2012版本的Microsoft.SqlServer.Types的几何UDT是否向后兼容SQL Server 2008?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在本地安装了SQL Server 2008和SQL Server 2012,则可以自己尝试一下.但是我只安装了较新的版本,并希望保持这种状态.

  • SQL Server 2008附带一个程序集Microsoft.SqlServer.Types.dll,主版本10.
  • SQL Server 2012随附一个程序集Microsoft.SqlServer.Types.dll,主版本11.

除其他事项外,两个程序集都公开了 SqlGeometryBuilder类型.两种程序集版本之间的一个显着区别是2012类型具有附加的重载方法AddCircularArc,而2008类型则没有.

由于同时引用这两者并不完全是琐碎的(也许是个坏主意)程序集,我想知道我是否只能使用2012年版本—甚至针对SQL Server 2008实例,只要我不使用AddCircularArc.

如果有人尝试过,可以分享他们的经验吗?

解决方案

默认情况下,SqlClient使用Microsoft.SqlServer.Types程序集的10.0版(即使您在项目中引用了较新的版本).当同时加载该程序集的两个不同版本时,您可能会看到奇怪的运行时异常,例如"System.InvalidCastException:无法将类型为"Microsoft.SqlServer.Types.SqlGeometry"的对象转换为类型为"Microsoft.SqlServer.Types.SqlGeometry"的对象. '." ...

下面的文章描述了将新的Microsoft.SqlServer.Types程序集与SqlClient结合使用的几种可能性: 对SQL Server 2012中的数据库引擎功能进行了重大更改

这些选项是:

  • 调用GetSqlBytes方法而不是Get方法(例如SqlGeometry.Deserialize(reader.GetSqlBytes(0)))
  • 在应用程序配置中使用程序集重定向
  • 为类型系统版本"属性指定"SQL Server 2012"的值,以强制SqlClient加载程序集的11.0版.

我个人更喜欢"Type System Version"连接字符串关键字.请在此处查看MSDN文章: SqlConnection.ConnectionString属性并搜索类型系统版本"

If I had both SQL Server 2008 and SQL Server 2012 installed locally, I would simply try this for myself; however I only have the newer version installed and would like to keep it that way.

  • SQL Server 2008 comes with an assembly Microsoft.SqlServer.Types.dll, major version 10.
  • SQL Server 2012 comes with an assembly Microsoft.SqlServer.Types.dll, major version 11.

Among other things, both assemblies expose a SqlGeometryBuilder type. The one notable difference between the two assembly versions is that the 2012 type has an additional overloaded method AddCircularArc, and the 2008 type does not.

Since it's not exactly trivial (and perhaps a bad idea) to reference both assemblies in parallel, I wonder whether I can just use the 2012 version — even against a SQL Server 2008 instance, as long as I don't make use of AddCircularArc.

Can anyone share their experience if they have tried this?

解决方案

By default SqlClient uses version 10.0 of the Microsoft.SqlServer.Types assembly (even if you reference a newer version in your project). When two different versions of that assembly are loaded at the same time you may see strange runtime exceptions like "System.InvalidCastException: Unable to cast object of type 'Microsoft.SqlServer.Types.SqlGeometry' to type 'Microsoft.SqlServer.Types.SqlGeometry'."...

The following article describes some possibilities that you have to use the newer Microsoft.SqlServer.Types assemblies with SqlClient: Breaking Changes to Database Engine Features in SQL Server 2012

The options are:

  • Calling the GetSqlBytes method, instead of the Get methods (e.g. SqlGeometry.Deserialize(reader.GetSqlBytes(0)))
  • Using assembly redirection in the application configuration
  • Specifying a value of "SQL Server 2012" for the "Type System Version" attribute to force SqlClient to load version 11.0 of the assembly

I personally favor the "Type System Version" connection string keyword. See the MSDN article here: SqlConnection.ConnectionString Property and search for 'Type System Version'.

这篇关于SQL Server 2012版本的Microsoft.SqlServer.Types的几何UDT是否向后兼容SQL Server 2008?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆