I know this question was asked for many times and I found a lot of information on Google regarding this problem, but I still can't solve the problem that exists on my DEV PC :(
Could not load file or assembly Microsoft.SqlServer.BatchParser
I installed Microsoft SQL Server 2005 Management Objects Collection as advised in many internet resources, but it did not help.
Then I tried to install Microsoft SQL Server 2008 Management Objects, but it says it can not be installed since newer version exists already (I have SQL Server 2008 installed).
Then I went to GAC, and found following lines:
Microsoft.SqlServer.BatchParser, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=AMD64
Microsoft.SqlServer.BatchParser, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=AMD64
Microsoft.SqlServer.BatchParser, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=x86
Microsoft.SqlServer.BatchParser, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=x86
Microsoft.SqlServer.BatchParserClient, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL <-- Should version 9.0.242.0 exist?
I already spent about half a day to find a solution without success, and it's very crappy to work with VS when IntelliSense does not work because of that error.
I have VS 2010 SQL Express 2005 and SQL Server 2008 installed (see configuration screenshot)
How can this dependency problem be solved?
NOTE: This answer is for people who are using MS SQL SMO (Management Objects) from a C# program.
I was struggling with the error mentioned in the question. The exact error I got was this:
Could not load file or assembly 'Microsoft.SqlServer.BatchParser.dll' or one of its dependencies. A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)
It ended up to be a problem with running .NET 2.0 assemblies within .NET 4.0 (or higher) CLR. The SQL server SMO assemblies are built against v2.0.50727 of the runtime and hence the following section is required in the app.config (or web.config)
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
The hint was in this discussion thread on MSDN forums.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With