尝试运行由 Visual Studio 的数据比较工具生成的脚本时会引发错误。通过谷歌搜索我找不到解决方案。
这发生在我在办公室尝试过的所有开发机器上。
我在 Microsoft SQL Sever Management Studio 2006 R2 中执行它,通过网络连接到远程服务器实例。
- Microsoft SQL Server 管理工作室 10.50.2550.0
- Microsoft 分析服务客户端工具 10.50.2500.0
- Microsoft 数据访问组件 (MDAC) 6.1.7601.17514
- 微软 MSXML3.0 4.0 5.0 6.0
- 微软 Internet Explorer 9.11.9600.16476
- 微软 .NET 框架 2.0.50727.5472
- 操作系统 6.1.7601
错误
Msg 6506, Level 16, State 10, Line 5
Could not find method 'WRITE' for type 'Microsoft.SqlServer.Types.SqlGeography' in assembly 'Microsoft.SqlServer.Types'
SQL
http://pastebin.com/embed_iframe.php?i=R9ResyeX
请注意,表格列“形状”被声明为;
[Shape] [geography] NULL
我试图更正生成的 TSQL,我根据http://technet.microsoft.com/en-us/library/microsoft.sqlserver.types.sqlgeography.write%28v=sql.105%29将 .WRITE 更改为 .Write 然后将.aspx去掉两个多余的NULL,从NULL参数结束。以防 SQL 自动将十六进制字符串转换为该方法期望的 BinaryWriter。这导致了预期的错误;
Msg 6564, Level 16, State 1, Line 1
The method 'Write' in class 'Microsoft.SqlServer.Types.SqlGeography' in assembly 'Microsoft.SqlServer.Types' has some invalid arguments. Value of type 'varbinary(528)' is not valid for argument number 0.
我不确定,但这看起来像是代码比较工具中的一个错误,它在哪里生成无效的 SqlGeography SQL 命令?
如果我们完全删除“.WRITE”并只保留 = 运算符,这看起来就像 TSQL 应该强制十六进制值的方式,因为它会更进一步。然而,我们得到另一个错误。
Msg 6522, Level 16, State 1, Line 13
A .NET Framework error occurred during execution of user-defined routine or aggregate "geometry":
System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
System.IO.EndOfStreamException:
at System.IO.BinaryReader.FillBuffer(Int32 numBytes)
at System.IO.BinaryReader.ReadDouble()
at Microsoft.SqlServer.Types.GeoData.Read(BinaryReader r)
at SqlGeometry::.DeserializeValidate(IntPtr , Int32 , CClrLobContext* )
我发现的唯一一篇涉及这个错误的文章是这个;
http://blogs.msdn.com/b/isaac/archive/2009/08/10/spatial-data-type-structure.aspx
但是,当谈到 Visual Studio 从源数据表中提取的 HEX 时,我并不明智。