2013-04-11 65 views
2

我在Azure上托管Restful服务。它运行良好。但是今天我用几何类型得到了一个异常。有什么有趣的,我没有更新任何东西。Azure Geomentry类型抛出异常无法加载文件或程序集microsoft.sqlserver.types版本= 11.0.0.0

我使用NuGet包引用microsoft.sqlserver.types版本= 10.0.0.0,它工作正常。

例外:

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,版本= 11.0.0.0,但没有成功。

找不到与此问题相关的任何问题。有人有这个问题吗?任何解决方案Azure发生了什么,它今天不起作用。 谢谢。

回答

2

找到解决方案:

http://www.microsoft.com/en-us/download/details.aspx?id=29065安装 “微软系统CLR类型为Microsoft®SQLServer®上2012” 的启动任务。

在项目的启动文件夹中复制SQLSysClrTypes.msi,并在同一文件夹中创建startup.cmd文件。注:应为 “复制到输出目录”= “始终复制”

ServiceDefenition.csdef

 
... 
&LTStartup> 
    &LTTask commandLine="Startup\Startup.cmd" executionContext="elevated" taskType="simple" />  
</Startup> 
... 

STARTUP.CMD

 
REM Install Sql Sys Clr Types 

cd /d "%~dp0" 

start /w msiexec /i SQLSysClrTypes.msi /qn 

而且现在的工作。

希望为某人节省时间。快乐编码...

1

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

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

请在官方博客文章read all about it

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方法,而不是上面列出的获取方法,来检索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及更高版本中可用。

相关问题