2

我在 Azure 上托管 Restful 服务。它工作得很好。但是今天我获得了具有几何类型的方法,使用抛出异常。有趣的是我没有更新任何东西。

我参考 microsoft.sqlserver.types, Version=10.0.0.0 使用了 NuGet 包,它运行良好。

例外:

System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> 
System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> 
System.Data.SqlClient.SqlException: An error occurred in the Microsoft .NET Framework while trying to load assembly id 1. The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE. Run the query again, or check documentation to see how to solve the assembly trust issues. For more information about this error: 
System.IO.FileNotFoundException: Could not load file or assembly 'microsoft.sqlserver.types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException: 
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)

at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
--- End of inner exception stack trace ---
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Entity.Internal.InternalContext.SaveChanges()
--- End of inner exception stack trace ---
at System.Data.Entity.Internal.InternalContext.SaveChanges()
at ...

我试图引用 microsoft.sqlserver.types, Version=11.0.0.0 但没有成功。

找不到与此问题相关的任何问题。有人有这个问题吗?有什么解决办法吗?以及在 Azure 发生的事情,它今天不起作用。谢谢。

4

3 回答 3

2

找到解决方案:

从http://www.microsoft.com/en-us/download/details.aspx?id=29065安装“Microsoft® System CLR Types for Microsoft® SQL Server® 2012”作为启动任务。

将 SQLSysClrTypes.msi 复制到项目的 Startup 文件夹中,并在同一文件夹中创建 startup.cmd 文件。注意:应该是“复制到输出目录”=“总是复制”

服务防御.csdef

...
<启动>
    <Task commandLine="Startup\Startup.cmd" executionContext="elevated" taskType="simple" />      
</启动>
...

启动.cmd

REM 安装 Sql Sys Clr 类型

cd /d "%~dp0"

启动 /w msiexec /i SQLSysClrTypes.msi /qn

它现在有效。

希望这可以为某人节省时间。快乐的编码...

于 2013-04-12T09:23:14.063 回答
1

ADO 团队现在发布了一个官方 NuGet 包来帮助解决这个问题。

  1. 安装Microsoft.SqlServer.Types NuGet 包
  2. 确保将适当版本的本机 SqlServerSpatial110.dll 程序集复制到输出目录并与您的应用程序一起部署。安装包时将在 Visual Studio 中打开的 ReadMe.txt 文件中包含有关如何执行此操作的步骤。

请在官方博客文章中阅读所有相关信息。

于 2014-01-31T00:37:21.030 回答
0

包含空间数据类型的程序集 Microsoft.SqlServer.Types.dll 已从版本 10.0 升级到版本 11.0。引用此程序集的自定义应用程序可能会失败。

这里有几个解决方案 https://msdn.microsoft.com/en-us/en-en/library/dn236441(v=sql.120).aspx

  1. 您可以通过调用 GetSqlBytes 方法而不是上面列出的 Get 方法来在代码中解决此问题,以检索 CLR SQL Server 系统类型,如以下示例所示

      string query = "SELECT [SpatialColumn] FROM [SpatialTable]";
      using (SqlConnection conn = new SqlConnection("..."))
      { 
            SqlCommand cmd = new SqlCommand(query, conn); 
    
            conn.Open(); 
            SqlDataReader reader = cmd.ExecuteReader(); 
    
            while (reader.Read()) 
            { 
                  // In version 11.0 only 
                  SqlGeometry g = SqlGeometry.Deserialize(reader.GetSqlBytes(0)); 
    
                  // In version 10.0 or 11.0 
                  SqlGeometry g2 = new SqlGeometry(); 
                  g.Read(new BinaryReader(reader.GetSqlBytes(0).Stream)); 
            } 
      } 
    
  2. 您可以通过在应用程序配置文件中使用程序集重定向来解决此问题,如以下示例所示:

     < assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         ...
         < dependentAssembly>
             < assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
             < bindingRedirect oldVersion="10.0.0.0" newVersion="11.0.0.0" />
         < /dependentAssembly>
         ...
     < /assemblyBinding>
    
  3. 您可以通过为“类型系统版本”属性指定值“SQL Server 2012”以强制 SqlClient 加载程序集的 11.0 版本来解决连接字符串中的此问题。此连接字符串属性仅在 .NET 4.5 及更高版本中可用。

于 2016-08-24T21:54:17.333 回答