Build SMO in .Net Framework 4.0

I use .net framework 4.0 and work on installing a web deployment, I refer to SQL Server 2008 SMO assemblies, and when I call the ExecuteNonQuery function in my setup using Smo Assemblies, it gives me this error: "Mixed mode combination built against version "v2.0.50727" of the runtime and cannot be loaded into runtime 4.0 without additional configuration information. " but sometimes it works correctly in my code, but for a while it gives this error,

I have the same class, the same method sometimes runs it correctly, and for a while it gives this error, I completely disappear with this error, I could not find any reason for this, and I also want to know that SMO assemblies available in .Net framework v4.0?

+6
source share
4 answers

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

This is a known issue. Using SMO for .Net 4.0 has not been signed 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> 
+10
source

Why are you using SMO builds to call ExecuteNonQuery?

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

+3
source

The real answer to using SMO in .NET v4 right now is here in a workaround:

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

+1
source

I myself ran into this problem, and adding the above tag (see @jimasp comment) doesn't seem to work, however I added it to app.config for the project where the code was located, however it was used as part of the console application. When I added it to the app.config console, it worked without any problems. I added it to the wrong app.config.

0
source

Source: https://habr.com/ru/post/903907/


All Articles