We help IT Professionals succeed at work.

Attempted to access an unloaded AppDomain in SMO Transfer in ASP.Net

hello all,

i have a module which creates a new database from the existing database by copying all tables and objects from the existing db. i am achieving this thru SMO Transfer . some times, it works fine. it throws error some time.

ERROR : errorCode=0 description=Attempted to access an unloaded AppDomain. helpFile=TableTransferGenerator Task helpContext=0 idofInterfaceWithError={8BDFE893-E9D8-4D23-9739-DA807BCDC2AC}

what is the cause of this error ? how can i solve this. somebody pls suggest..

note:- if i close .Net IDE and reopen, and then run the project..it works.(!).

Thanks for any help.
Watch Question

From the error and the fix it is clear that when you are calling some functionality\use some dll, it is already unloaded and you need to reintialize the object. When you close your application and restart it, it does. So, probably there is either some exception which is not handled or you are not closing the application after the module is unloaded.


Thanks for ur comment. here is the code i am using. can you pls point out where i am doing wrong? (it works fine most of the time..it displays that error some times! ..at that time, the db is created..transfer is not executing).

Dim MasterDbse As String = "MY SOURCE DB"
Dim strDatabaseName as String="The new DB NAME"
            Dim conn As New ServerConnection("MY_SERVER")

            conn.LoginSecure = False

            conn.Login = dbUser

            conn.Password = dbPass

            Dim serverCon As New Server(conn)

            Dim newdb As New Database(serverCon, strDatabaseName)

 Dim transfer As New Transfer(serverCon.Databases(MasterDbse))

            With transfer

                .CopyAllObjects = True

                .CopyAllTables = True

                .CopyData = True

                .CopyAllUsers = True

                .DestinationDatabase = newdb.Name

                .DestinationLoginSecure = False

                .DestinationLogin = dbUser

                .DestinationPassword = dbPass

                .DestinationServer = serverCon.Name

                 .CopySchema = True

            End With

            With transfer.Options

                .WithDependencies = True

                .ContinueScriptingOnError = True

                .NoIdentities = False

                .NoCollation = True

                .Default = True

                .Indexes = True

                .DriDefaults = True

                .DriAllKeys = True

                .DriForeignKeys = True

                .DriIndexes = True

                .DriPrimaryKey = True

                .DriUniqueKeys = True

            End With

 ' in this line, it points the error in my error log
Catch ex as Exception
End Try

Open in new window

ok. Finally i used Backup & Restore method of SMO.. it is fast and produces no errors.


used alternative method