Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load Microsoft.SqlServer.BatchParser or one of its dependencies

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 :(
I have that ugly error message on every page

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) enter image description here

How can this dependency problem be solved?

like image 694
Alex Dn Avatar asked Sep 24 '12 08:09

Alex Dn


1 Answers

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.

like image 141
Sudhanshu Mishra Avatar answered Sep 19 '22 09:09

Sudhanshu Mishra