SQL Server Developer Center > SQL Server Forums > SQL Server SMO/DMO > faile copy database on same sql server (2005) error out on user or role even with CopyAllRoles set false
Ask a questionAsk a question
 

Answerfaile copy database on same sql server (2005) error out on user or role even with CopyAllRoles set false

  • Friday, October 16, 2009 6:23 PMJohn Tian Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I am running this code as script task in ssis 2005
    here is my code:
    -----------
    Public Sub Main() 

     

    Dim dbSourceName As String = "YSCMII"

     

    Dim dbDestName As String = "YSCMII_COPY" 

     

    Dim conn As New ServerConnection

    conn.LoginSecure =

    False

    conn.Login =

    "user"

    conn.Password =

    "password"

    conn.ServerInstance =

    "slcsqltest1"

     

    'Connect to the remote SQL Server.

     

    Dim srv As Server

    srv =

    New Server(conn)

     

    'The actual connection is made when a property is retrieved.

    Console.WriteLine(srv.Information.Version) 

     

    'Reference the source database

     

    Dim db As Database

    db = srv.Databases(dbSourceName)

     

    'Create a new database that is to be destination database.

     

    Dim dbCopy As Database

    dbCopy =

    New Database(srv, dbDestName)

     dbCopy.Create() 

     

    'Define a Transfer object and set the required options.

     

    Dim xfr As Transfer

    xfr =

    New Transfer(db)

    xfr.CopyAllTables =

    True

    xfr.Options.WithDependencies =

    True

    xfr.Options.ContinueScriptingOnError =

    True

    xfr.DestinationDatabase = dbCopy.Name

    xfr.DestinationServer = srv.Name

    xfr.DestinationLoginSecure =

    True

    xfr.CopyAllRoles =

    False

    xfr.CopySchema =

    True

     

    'Include data

    xfr.CopyData =

    False

     

     

    'Execute the transfer

    xfr.TransferData() 

    Dts.TaskResult = Dts.Results.Success

     

    End Sub

     

     

    ------------

    Error I got as following:

    script Task: The script threw an exception: ERROR : errorCode=-1073548784 description=Executing the query "EXEC dbo.sp_grantdbaccess @loginame = N'ppenzance', @name_in_db = N'ppenzance'

    " failed with the following error: "User or role 'ppenzance' already exists in the current database.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

    helpFile= helpContext=0 idofInterfaceWithError={8BDFE893-E9D8-4D23-9739-DA807BCDC2AC}

    Task failed: Script Task

    Thanks!

Answers

All Replies