Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET--IIS7--IBM DB2问题_Asp.net_Iis_Iis 7_Db2 - Fatal编程技术网

ASP.NET--IIS7--IBM DB2问题

ASP.NET--IIS7--IBM DB2问题,asp.net,iis,iis-7,db2,Asp.net,Iis,Iis 7,Db2,我正在一个ASP.NET网站上工作,该网站调用DB2数据库。我已经在Windows 2008服务器上安装了Visual Studio,该站点将在该服务器上托管。当我在VisualStudio中调试站点时,使用集成的web服务器,我可以连接到数据库,站点运行良好。当我在IIS7中在同一台服务器上设置站点时,由于以下错误,我无法访问该站点或数据库 以下是技术细节: Windows 2008 Server IIS 7 Visual Studio 2010 Premium DB2 v9.5.301.43

我正在一个ASP.NET网站上工作,该网站调用DB2数据库。我已经在Windows 2008服务器上安装了Visual Studio,该站点将在该服务器上托管。当我在VisualStudio中调试站点时,使用集成的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
我不明白该网站如何使用VisualStudioWeb服务器运行良好,而不在IIS中工作。我不知道这是IIS问题还是我正在使用的IMB.Data.DB2.dll版本的问题。如果有人有解决方案或想法,我们将不胜感激


谢谢。

您的AppDomain中的.Net framework版本似乎有误。在AppDomain设置中,确保选择的.Net framework版本与IBM.Data.DB2程序集的版本相匹配。

要实现这一点,我必须进入IIS管理器,单击应用程序池节点,单击站点的应用程序池,然后单击屏幕右侧的高级设置。然后我将Enable 32位应用程序更改为true


这解决了我的问题,并且站点运行正常。

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


最简单的解决方案是添加一个生成后脚本,以便在每次生成后从bin文件夹中删除该DLL。这样,IIS将能够在GAC中找到正确的版本(是否需要32位或64位版本取决于您的应用程序池设置)。

在Visual Studio中:右键单击有问题的引用,并将Copy Local更改为“False”

更多信息:

谢谢您的回复。我试过了,但没用。我能找到问题的答案谢谢你,它解决了我的问题。我来看看是否能阻止最初的复制。顺便说一句,Visual Studio 2015也会出现这种情况。我将DLL复制到了bin中。当我删除它时,我不再收到此错误。这会修复错误,但会强制应用程序以32位运行。真正的解决方案是从bin文件夹中删除32位的IBM.Data.DB2.dll,以便IIS可以在GAC中找到正确的(64位)版本。@MarcSelis非常感谢,您的评论有帮助:)