Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SMO Assemblies in .Net Framework 4.0

I am using .net framework 4.0 and working on Web deployment Setup, I have referenced the SMO Assemblies of sql server 2008, and When I Call ExecuteNonQuery Function in my setup using Smo Assemblies it gives me this error "Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information." but sometimes it works correctly in my code but some time it gives this error,

I have using the same class, same method sometimes its run correctly and some time it gives this error, I am completely fade up with this error, I couldn't find any reason for that and I also want to know is SMO assemblies are available in .Net framework v4.0?

like image 806
Arun Kumar Avatar asked Dec 16 '11 13:12

Arun Kumar


3 Answers

From: http://social.msdn.microsoft.com/Forums/en-US/sqlsmoanddmo/thread/533f7044-1109-4b7a-a697-2621f23017d6

This is a known issue. SMO's usage against .Net 4.0 hasnt been signed off or announced by microsoft.

There is an unsupported option to get this working (add this to your app.config):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>
like image 155
jimasp Avatar answered Nov 12 '22 16:11

jimasp


Why are you using "SMO assemblies" to call ExecuteNonQuery?

Why not just reference and use ADO.NET? See System.Data.SqlClient.ExecuteNonQuery(...)

like image 43
Mike Atlas Avatar answered Nov 12 '22 14:11

Mike Atlas


The real answer for using SMO in .NET v4 right now seems to be here in the workaround:

http://connect.microsoft.com/SQLServer/feedback/details/643811/net-4-0-compatible-smo

like image 32
Bill Forney Avatar answered Nov 12 '22 16:11

Bill Forney