ASP.NET - IIS7 - IBM DB2问题

use*_*300 11 asp.net iis db2 iis-7

我正在一个调用DB2数据库的ASP.NET网站上工作.我在托管该站点的Windows 2008服务器上安装了Visual Studio.当我在Visual Studio中调试站点时,使用集成的Web服务器,我可以连接到数据库,并且站点运行正常.当我在IIS7中设置站点时,在同一台服务器上,由于以下错误,我无法访问该站点或数据库.

以下是技术细节:

Windows 2008 Server
IIS 7
Visual Studio 2010 Premium
DB2 v9.5.301.436

Could not load file or assembly 'IBM.Data.DB2' or one of its dependencies. An attempt was made to load a program with an incorrect format. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.BadImageFormatException: Could not load file or assembly 'IBM.Data.DB2' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Assembly Load Trace: The following information can be helpful to determine why the assembly 'IBM.Data.DB2' could not be loaded.

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. 

Stack Trace: 

[BadImageFormatException: Could not load file or assembly 'IBM.Data.DB2' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +567
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +192
   System.Reflection.Assembly.Load(String assemblyString) +35
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +118

[ConfigurationErrorsException: Could not load file or assembly 'IBM.Data.DB2' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11424435
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +484
   System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +127
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +334
   System.Web.Compilation.BuildManager.CallPreStartInitMethods() +280
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1167

[HttpException (0x80004005): Could not load file or assembly 'IBM.Data.DB2' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11556592
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4813333
Run Code Online (Sandbox Code Playgroud)

我不明白该网站如何使用Visual Studio Web服务器正常运行,而不是在IIS中工作.我不知道这是一个IIS问题,还是我正在使用的IMB.Data.DB2.dll版本的问题.如果有人有解决方案或任何想法,他们将不胜感激.

谢谢.

use*_*300 17

要完成这项工作,我必须进入IIS管理器,单击应用程序池节点,单击该站点的应用程序池,然后单击屏幕右侧的高级设置.然后我将启用32位应用程序更改为true.

这解决了我的问题,网站运行正常.

  • 这可以修复错误,但会强制您的应用程序以32位运行.真正的解决方案是从bin文件夹中删除32位IBM.Data.DB2.dll,以便IIS可以在GAC中找到正确的(64位)版本. (2认同)

Mar*_*lis 5

出于某些奇怪的原因,Visual Studio 2012(及更高版本)始终将32位版本的IBM.Data.DB2.dll复制到您的bin文件夹,即使这不是必需的,因为在安装DB2 Connect时该DLL已注册GAC.

最简单的解决方案是添加一个构建后脚本,以便在每次构建后从bin文件夹中删除该DLL.这样,IIS就能够在GAC中找到正确的版本(无论是需要32位还是64位版本,取决于您的AppPool设置).


Dav*_*vid 0

听起来您的 AppDomain 中的 .Net 框架版本错误。在 AppDomain 设置中,确保选择的 .Net Framework 版本与 IBM.Data.DB2 程序集的版本匹配。