我可以通过只部署的DLL使用SQL Server CE在中等信任环境 [英] Can I use SQL Server CE in a medium trust environment by just deploying the DLLs

查看:249
本文介绍了我可以通过只部署的DLL使用SQL Server CE在中等信任环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的是使用SQL Server CE 4.0数据库中的ASP.NET 4.0应用程序。这是所有工作使用中等信任(信任相同配置的主机供应商)我的开发环境。在这台机器,我已经完成安装过程了(下载并安装了MSI)​​。现在我想部署该解决方案,我的网络托管商。

I've written an ASP.NET 4.0 application that is using a SQL Server CE 4.0 database. This is all working on my development environment using Medium Trust (same trust config as the hoster). On this machine, I've gone through the install process (downloaded and installed the MSI). I'm now trying to deploy this solution to my web hoster.

这是正在运行的code是(这是Altairis成员资格提供的直出副本:

The code that is running is (this is a straight out copy of the Altairis Membership Provider:

using (HostingEnvironment.Impersonate())
using (var db = this.connectionString.CreateDbConnection())
using (var cmd = this.CreateDbCommand("SELECT PasswordHash, PasswordSalt FROM $Users WHERE UserName = @UserName AND IsApproved = 1", db)) 
{
     cmd.AddParameterWithValue("@UserName", username);
     db.Open();

     // Validate password
     using (var r = cmd.ExecuteReader()) { .. snip.. }
 }

在上面的实例中,分贝的DbConnection CMD 的DbCommand

In the instance above, db is DbConnection, and cmd is DbCommand

我收到以下错误:

[出现InvalidOperationException:无法执行CAS断言在安全透明的方法]
  System.Security。codeAccessSecurityEngine.CheckNReturnSO(PermissionToken
  permToken,codeAccessPermission需求,StackCrawlMark&安培; stackMark,
  INT32创造)+ 0结果
  System.Security。codeAccessSecurityEngine.Assert(codeAccessPermission
  帽,StackCrawlMark&安培; stackMark)+61结果
  System.Security。codeAccessPermission.Assert()+28结果
  System.Data.SqlServerCe.KillBitHelper.GetKillBit()+231结果
  System.Data.SqlServerCe.KillBitHelper..cctor()+56

[InvalidOperationException: Cannot perform CAS Asserts in Security Transparent methods] System.Security.CodeAccessSecurityEngine.CheckNReturnSO(PermissionToken permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 create) +0
System.Security.CodeAccessSecurityEngine.Assert(CodeAccessPermission cap, StackCrawlMark& stackMark) +61
System.Security.CodeAccessPermission.Assert() +28
System.Data.SqlServerCe.KillBitHelper.GetKillBit() +231
System.Data.SqlServerCe.KillBitHelper..cctor() +56

[TypeInitializationException:为System.Data.SqlServerCe.KillBitHelper'的类型初始值引发了异常]结果
  System.Data.SqlServerCe.KillBitHelper.ThrowIfKillBitIsSet()+ 0结果
  System.Data.SqlServerCe.SqlCeProviderFactory..cctor()+41

[TypeInitializationException: The type initializer for 'System.Data.SqlServerCe.KillBitHelper' threw an exception.]
System.Data.SqlServerCe.KillBitHelper.ThrowIfKillBitIsSet() +0
System.Data.SqlServerCe.SqlCeProviderFactory..cctor() +41

[TypeInitializationException:对的类型初始值System.Data.SqlServerCe.SqlCeProviderFactory抛出一个异常]

[TypeInitializationException: The type initializer for 'System.Data.SqlServerCe.SqlCeProviderFactory' threw an exception.]

[TargetInvocationException:异常已被调用的目标引发异常]结果
  System.RuntimeFieldHandle.GetValue(RtFieldInfo领域,对象实例,RuntimeType的字段类型,RuntimeType declaringType,布尔和放大器;
  domainInitialized)+ 0结果
  System.Reflection.RtFieldInfo.InternalGetValue(obj对象,布尔doVisibilityCheck,布尔doCheckConsistency)180结果
  System.Reflection.RtFieldInfo.GetValue(obj对象)+8结果
  System.Data.Common.DbProviderFactories.GetFactory(DataRow的providerRow)+232结果
  System.Data.Common.DbProviderFactories.GetFactory(字符串providerInvariantName)+88结果
  Altairis.Web.Security.DatabaseExtensionMethods.CreateDbConnection(ConnectionStringSettings
  设置)在DatabaseExtensionMethods.cs:19结果
  Altairis.Web.Security.TableMembershipProvider.ValidateUser(字符串
  用户名,字符串密码)在TableMembershipProvider.cs:361

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeFieldHandle.GetValue(RtFieldInfo field, Object instance, RuntimeType fieldType, RuntimeType declaringType, Boolean& domainInitialized) +0
System.Reflection.RtFieldInfo.InternalGetValue(Object obj, Boolean doVisibilityCheck, Boolean doCheckConsistency) +180
System.Reflection.RtFieldInfo.GetValue(Object obj) +8
System.Data.Common.DbProviderFactories.GetFactory(DataRow providerRow) +232
System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +88
Altairis.Web.Security.DatabaseExtensionMethods.CreateDbConnection(ConnectionStringSettings settings) in DatabaseExtensionMethods.cs:19
Altairis.Web.Security.TableMembershipProvider.ValidateUser(String username, String password) in TableMembershipProvider.cs:361

我用反编译通过code看,它似乎是的SQL Server CE的内部正在寻找一个注册表项,然后试图做一个code 断言()

I've used a decompiler to look through the code, and it seems that the internals of SQL Server CE are looking for a registry entry and then trying to do a code Assert().

是否可以使用SQL Server CE 4.0在部分信任的环境中,只需 \\ BIN 部署DLL ??

Is it possible to use SQL Server CE 4.0 in a partial trust environment, by just \bin deploying the DLL ??

推荐答案

是的,只要您的主机托管服务提供商允许它 - 它在默认情况下在ASP.NET 4.0允许的。确保你使用的程序集版本4.0.0.0(而不是4.0.0.1)。在这里阅读更多: HTTP://erikej.blogspot .COM / 2011/10 / SQL服务器紧凑-40-下aspnet.html

Yes, provided your hoster allows it - it is allowed by default in ASP.NET 4.0. Make sure you use assembly version 4.0.0.0 (and not 4.0.0.1). Read more here: http://erikej.blogspot.com/2011/10/sql-server-compact-40-under-aspnet.html

这篇关于我可以通过只部署的DLL使用SQL Server CE在中等信任环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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