18

I wrote an asp.net web app which uses SMO against SQL Server 2008 to be able to run some DB scripts. It references these assemblies (in the C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies folder):

Microsoft.SqlServer.ConnectionInfo
Microsoft.SqlServer.Management.Sdk.Sfc
Microsoft.SqlServer.Smo

The microsoft.sqlserver.batchparser.dll is not in this folder. Locally (32 bits machine, IIS7) I have no issue.

When I publish the app to my hosting provider (discountasp.net, SQL Server 2008, IIS7, 32bits too), I get this error:

Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

I searched my local machine and I can't find this assembly. However it works well on this machine.

The "Microsoft SQL Server 2008 Setup Discovery Report" tool reports I have v10.1.2531.0 installed locally.

CJBS
  • 15,147
  • 6
  • 86
  • 135
Nicolas Cadilhac
  • 4,680
  • 5
  • 41
  • 62

10 Answers10

11

To get this dll, you will need to install the Microsoft SQL Server 2008 Management Objects (available from here). That particular dll gets installed into the GAC, which is why you probably cannot find it using a search.

As you are using a hosting provider, it would appear that they do not have this installed. Your choices are to get it installed by them (which is probably unlikely), or deploy the dll manually (which may be on dodgy licencing ground).

skolima
  • 31,963
  • 27
  • 115
  • 151
adrianbanks
  • 81,306
  • 22
  • 176
  • 206
  • When I try to install SMO, the installer says I already have a higher version installed. Since I am able to reference Microsoft.SqlServer.Smo from my project, I guess this confirms it. – Nicolas Cadilhac Oct 20 '10 at 19:09
  • 1
    @Nicolas: yes, you will have this installed locally. It is not however installed on your hosting provider, hence the problem you are having. – adrianbanks Oct 20 '10 at 19:11
  • Calling gacutil /l shows me batchparser is in the GAC, however the references dialog box in VS2010 won't show it to me. Going manually into the GAC to extract the assembly and it is in the GAC_32 folder, not GAC_MSIL. Anyway, adding this to Reflector shows it has a reference to Microsoft.VisualC.... pretty odd. – Nicolas Cadilhac Oct 20 '10 at 19:15
  • 3
    @Nicolas: according to [this](http://blogs.msdn.com/b/mwories/archive/2005/05/02/smofaq.aspx) page, that particular dll is platform-specific (ie. there are both 32 and 64 bit versions). – adrianbanks Oct 20 '10 at 19:21
  • I have no idea how to deploy SMO on my hosting provider... See my other comment in the other answer (for the GAC). I can't install the latest "Microsoft SQL Server 2008 Feature Pack, April 2009" either (hoping to find redistributable package inside) because it always complain I have something newer already installed – Nicolas Cadilhac Oct 20 '10 at 19:59
  • @Nicolas: You could manually extract the dll from the msi (instructions [here](http://www.adrianbanks.co.uk/?p=64)) and deploy that, but I'm not sure what the licencing implications are. – adrianbanks Oct 20 '10 at 22:12
  • Here is an updated link to a newer version http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=3522 – Todd Smith Apr 16 '12 at 18:23
  • How about a NuGet package? – Triynko Oct 20 '20 at 19:04
6

First you need to enable browsing of GAC folder:

1. go to Registry Editor (RUN > regedit)
2. go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion
3. Right click Fusion > NEW > DWORD
4. Type DisableCacheViewer
5. Double click DisableCacheViewer
6. Set value to 1

then you can find it here
C:\Windows\assembly\GAC_32\Microsoft.SqlServer.BatchParser\10.0.0.0__89845dcd8080cc91

evilom
  • 573
  • 6
  • 19
2

I had a similar issue, but with R2. For me it worked by installing Microsoft® SQL Server® 2008 R2 Shared Management Objects and dependant Microsoft® System CLR Types for SQL Server® 2008 R2.

Find them here http://www.microsoft.com/en-us/download/confirmation.aspx?id=16978

Alvis
  • 3,543
  • 5
  • 36
  • 41
2

You need to have the SMO components installed on your hosting provider as well. You can download them here.

Joe Stefanelli
  • 132,803
  • 19
  • 237
  • 235
2

I resolve this only Just Right Click on Project navigate to Properties and Change Platform Target from 'Any' to 'x86'

failed to load microsoft.sqlserver.batchparser

nbk
  • 45,398
  • 8
  • 30
  • 47
Naeem Ahmed
  • 216
  • 1
  • 6
0

You could install the SQL Client Connection feature from the SQL Server DVD as well. I installed that as well as the SDK components to resolve this issue while installing SolarWinds.

Ernest Correale
  • 451
  • 3
  • 5
0

I had SMO x64 installed, but SMO x86 was required on build server.

Der_Meister
  • 4,771
  • 2
  • 46
  • 53
0
 <startup useLegacyV2RuntimeActivationPolicy="true"> in App.config
Andrew
  • 784
  • 9
  • 15
0

This happened to me today. Running as administrator did the trick for me, I'm not sure why.

It's not ideal for production, but might work just fin for development environments.

0

Install the 'Microsoft Visual C++ 2013 Redistributable (x86)' if it is not showing up in add/remove programs.

jo0ls
  • 389
  • 1
  • 9