none
SMO ExecuteNonQuery issue in .net 4.0 RRS feed

  • Question

  • I've just upgraded a project to .net 4.0, I'm getting an odd error using ExecuteNonQuery:

    Errors: {"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 infor

     

     

      Dim xServer As Server = New Server(SQLServer)
     Dim db As New Database(xServer, Database)
     db = xServer.Databases(Database)
     Dim xUser As New User(db, LoginName)
     xUser.UserType = UserType.SqlLogin
     xUser.Login = LoginName
    
    db.ExecuteNonQuery("sp_change_users_login 'auto_fix',testuser;") 
     

    Is this a known problem?

    Saturday, October 16, 2010 2:35 AM

Answers

  • Hi madlan,

     

    "Is there an issue with SMO in .NET 4 then? I'm using the latest version."

     

    -> For this issue, please check the following similar cases for detailed discussion/explanation.

     

    1 Thread: SMO in .NET 4.0

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

     

    Quote from Microsoft Engineer:

    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.

    <configuration> 

      <startup useLegacyV2RuntimeActivationPolicy="true"> 

        <supportedRuntime version="v4.0"/> 

      </startup> 

    </configuration> 

     

     

    2 Feedback: Unable to deploy VSTO referencing SQL SMO after installing VS2010  Microsoft Connect

    https://connect.microsoft.com/VisualStudio/feedback/details/524869

     

    Quote from Microsoft Engineer:

    Posted by Microsoft on 1/27/2010 at 12:55 PM

    Hi Jake
    I was able to confirm that the SMO dll that ships with VS2010 is indeed and inplace update that has a dependency on the STrace dll. This explains why the STrace dll shows up in the manifest when building the project with VS2010.

    If you don't want to take on this additional dependency then you will have to continue building against the older SMO dll.
    I am resolving this bug as by design. Feel free to reply back if you have any questions.

    Thanks
    Saurabh

     

     

    Best regards,

    Martin Xie

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by madlan Saturday, October 23, 2010 7:29 PM
    Wednesday, October 20, 2010 6:56 AM
    Moderator

All replies

  • Hi madlan,

     

    Welcome to MSDN forums.

     

    If your application has a dependency on an assembly built in .NET 2 Framework, and if you try to run your application when it has been built in.NET 4. you will encounter such an error as below.

     

    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.

     

    To fix this, you need to add the useLegacyV2RuntimeActivationPolicy attribute to the application configure file in the same folder or your app, e.g appname.exe.config. The config file should read as follows: 

    <configuration> 

      <startup useLegacyV2RuntimeActivationPolicy="true"> 

        <supportedRuntime version="v4.0"/> 

      </startup> 

    </configuration> 

     

    You can check the following similar cases for reference.

    1)       http://social.msdn.microsoft.com/Forums/en-US/clr/thread/58271e39-beca-49ac-90f9-e116fa3dd3c0

    2)       http://blog.yusri.com.my/v2/article.php/dotnet2asmindotnet4

    3)       http://stackoverflow.com/questions/1604663/what-does-uselegacyv2runtimeactivationpolicy-do-in-the-net-4-config

     

     

    Best regards,

    Martin Xie

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, October 19, 2010 11:19 AM
    Moderator
  • Thanks Martin, that allows it to compile ok.
    Is there an issue with SMO in .NET 4 then? I'm using the latest version.

    Thanks.
    Tuesday, October 19, 2010 6:33 PM
  • Hi madlan,

     

    "Is there an issue with SMO in .NET 4 then? I'm using the latest version."

     

    -> For this issue, please check the following similar cases for detailed discussion/explanation.

     

    1 Thread: SMO in .NET 4.0

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

     

    Quote from Microsoft Engineer:

    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.

    <configuration> 

      <startup useLegacyV2RuntimeActivationPolicy="true"> 

        <supportedRuntime version="v4.0"/> 

      </startup> 

    </configuration> 

     

     

    2 Feedback: Unable to deploy VSTO referencing SQL SMO after installing VS2010  Microsoft Connect

    https://connect.microsoft.com/VisualStudio/feedback/details/524869

     

    Quote from Microsoft Engineer:

    Posted by Microsoft on 1/27/2010 at 12:55 PM

    Hi Jake
    I was able to confirm that the SMO dll that ships with VS2010 is indeed and inplace update that has a dependency on the STrace dll. This explains why the STrace dll shows up in the manifest when building the project with VS2010.

    If you don't want to take on this additional dependency then you will have to continue building against the older SMO dll.
    I am resolving this bug as by design. Feel free to reply back if you have any questions.

    Thanks
    Saurabh

     

     

    Best regards,

    Martin Xie

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by madlan Saturday, October 23, 2010 7:29 PM
    Wednesday, October 20, 2010 6:56 AM
    Moderator