5

I have a small app which references the Microsoft.SqlServer.Smo assembly (so I can display to the user a list of servers & databases to which they can connect).

My application originally referenced Microsoft.SqlServer.Smo and Microsoft.SqlServer.ConnectionInfo. Things worked as expected on my dev box.

When I installed the application on a test machine, I received a System.IO.FileNotFoundException. The details of the message included the following: Could not load file or assembly Microsoft.SqlServer.SmoEnum

I eventually resolved the issue by referencing the following assemblies in addition to the ones mentioned above:

  • Microsoft.SqlServer.SmoEnum
  • Microsoft.SqlServer.SqlEnum
  • Microsoft.SqlServer.BatchParser
  • Microsoft.SqlServer.Replication

Can anyone confirm that I do indeed need to include each of these additional assemblies in my application (and therefore install them on user's machines) even though the app builds fine on my development box without them referenced?

Tim Lentine
  • 7,782
  • 5
  • 35
  • 40

4 Answers4

4

You need to install two MSI files on a target machine, namely:

1) SQLSysClrTypes.msi [this one is needed for C# -> SMO GAC]

2) SharedManagementObjects.msi

For SQL Server 2014 you can dowload these here.

Also, you must make sure that the version is correct. These two files can be found with a little bit of googling. This way you don't copy anything to local & they will be resolved from GAC.

I know that this is old question, but the answers weren't satisfactory.

btlog
  • 4,760
  • 2
  • 29
  • 38
Erti-Chris Eelmaa
  • 25,338
  • 6
  • 61
  • 78
2

Yes, they do need to be included. On the development machine you probably have SQL Server installed, which places those assemblies into the Global Assembly Cache. Whenever you build, Visual Studio just pulls from them from the GAC. It also assumes that the GAC of whatever computer it will be deployed on will also have those files. If not, it throws the FileNotFound exception.

David J. Sokol
  • 3,456
  • 3
  • 31
  • 25
0

For me this answer turned out not to be true. I added the above references but with no resolution. Ultimately I found that I only needed the reference:

Microsoft.SqlServer.Smo

... and the following resolution:

I get a "An attempt was made to load a program with an incorrect format" error on a SQL Server replication project

To summarize, I needed to enable my IIS 6 to enable 32bit application on IIS App pool. This is because I had Win 7 x64 but a SQL x86 install. Too bad the error message can't be more specific huh?

Community
  • 1
  • 1
ebol2000
  • 1,195
  • 11
  • 16
  • To follow up... when deploying to to my test webserver, I ran into the error above. I was puzzled and so looked in the GAC and found all of the dlls mentioned above. However, in my web application's bin directory, I noticed I had only: Microsoft.SqlServer.BatchParser Microsoft.SqlServer.Replication ... so I removed them and everything worked. I believe my partial set of the dependent files was causing .net to load my partial set of files in the bin and not from the GAC as it should have been. Therefore, it appears the best practice is to not do deploy these interops. – ebol2000 Apr 27 '11 at 23:27
0

Since JIT links to external assemblies at run-time, this question can't be answered without analyzing your code and seeing what you call and in turn, what those calls call, etc.

If you want to analyze this yourself, your best bet would be to reference only the assembly you need and then to learn from the exceptions and inner-exceptions what happened.

Another thing you should look into is why the four assemblies you mention aren't in the GAC. It sure seems like they should be.

Omer van Kloeten
  • 11,800
  • 9
  • 42
  • 53