This SMO transfer script doesnt transfer ?

Hello, this takes a lot of time  but when I got to sql server management studio there are no objects there!!

What am I missing

private
void button1_Click(object sender, EventArgs e)

{

Server sv = new Server("ESTACION15");

Database db = sv.Databases["GescomDllo"] ;

Database db2 = new Database(sv, "PRUEBA");

// db2.Create();

Transfer xfr;

xfr = new Transfer(db);

xfr.CopyAllObjects=true;

xfr.CopyAllTables = true;

xfr.Options.WithDependencies = true;

xfr.Options.ContinueScriptingOnError = true;

xfr.DestinationDatabase = "PRUEBA";

xfr.DestinationServer = sv.Name;

xfr.DestinationLoginSecure = true;

xfr.CopySchema = true;

//'Script the transfer. Alternatively, perform immediate data transfer with TransferData method.

xfr.ScriptTransfer();

}




Answer this question

This SMO transfer script doesnt transfer ?

  • Nasty

     Luis Esteban Valencia MCP. wrote:
    It didnt work, the strange thing is that it doesnt throw exceptions.

    I go to management studio after it and there are no tables on the database PRUEBA.

    the scripttransfer method takes more than 5 minutes and it seems is not making anything.

    Thanks



    It creates the database but nothing else happens.

    This is the code


    private void button1_Click(object sender, EventArgs e)

    {

    try {

    Server sv = new Server("ESTACION15");

    Database db = sv.Databases["GescomDllo"];

    Database db2 = new Database(sv, "PRUEBA");

    db2.Create();

    Transfer xfr;

    xfr = new Transfer(db);

    xfr.DestinationServer = "ESTACION15";

    xfr.DestinationLogin = "gescom";

    xfr.DestinationPassword = "gescom";

    xfr.CopyAllObjects = true;

    xfr.Options.WithDependencies = true;

    xfr.Options.ContinueScriptingOnError = false;

    xfr.DestinationDatabase = "PRUEBA";

    //'Script the transfer. Alternatively, perform immediate data transfer with TransferData method.

     

    xfr.ScriptTransfer();

    xfr.TransferData();

    richTextBox1.Text = xfr.ToString();

    }

    catch (Exception ex)

    {

    richTextBox1.Text = ex.Message;

    }

    }


     



  • Liew Vai Teng

    Are you still having a problem with this transfer   Are you actually getting a script when calling xfr.ScriptTransfer()   If you are getting a script, do you get any errors when you execute the script manually   If ScriptTransfer() is working, the next step would be to trace the activity on the destination server during TransferData().  This will help to narrow down the problem.  Please let us know what you find.

    Peter

  • Drea27

    The easiest way to see the script is like the following -- let me know if you are getting a script

    System.Collections.Specialized.StringCollection script = new StringCollection();

    script = trans.ScriptTransfer();

    foreach (String str in script)

    {

        Console.WriteLine("GO");

        Console.WriteLine(str);

    }

    Peter



  • Kripa

     Luis Esteban Valencia MCP. wrote:
    I had it commented because the database was already created.

    I removed

    xfr.CopyAllTables = true; and left

    xfr.CopyAllObjects =
    true;



    It still doesnt work

    private void button1_Click(object sender, EventArgs e)

    {

    try {

    Server sv = new Server("ESTACION15");

    Database db = sv.Databases["GescomDllo"];

    Database db2 = new Database(sv, "PRUEBA");

    Transfer xfr;

    xfr = new Transfer(db);

    xfr.DestinationServer = "ESTACION15";

    xfr.DestinationLogin = "gescom";

    xfr.DestinationPassword = "gescom";

    xfr.CopyAllObjects = true;

    xfr.Options.WithDependencies = true;

    xfr.Options.ContinueScriptingOnError = false;

    xfr.DestinationDatabase = "PRUEBA";

    //'Script the transfer. Alternatively, perform immediate data transfer with TransferData method.

    xfr.ScriptTransfer();

    }

    catch (Exception ex)

    {

    richTextBox1.Text = ex.Message;

    }

    }




    Still waiting for help, or is this a bug in sql 2005

  • Steven Ramacher

    The Transfer object has properties that you can set to tell it what to copy, like CopyAllUsers and so on. It also has a ScriptingOptions object called Options that has properties you can set.

    xfr.CopyAllUsers = false;

    and

    xfr.Options.Permissions = false;

    Also, make sure the connection you are using has appropriate permissions.


  • nukthem

    It doesnt transfer   

  • FreddieCode

    ScriptTransfer() just creates the scripts, it doesn't execute them. You need to call ExecuteNonQuery on the new database object, passing the StringCollection containing the generated scripts as a parameter.

    Dim strColl As StringCollection

    strColl = xsfr.ScriptTransfer()

    db.ExecuteNonQuery(strColl)


  • Hiya

    It didnt work, the strange thing is that it doesnt throw exceptions.

    I go to management studio after it and there are no tables on the database PRUEBA.

    the scripttransfer method takes more than 5 minutes and it seems is not making anything.

    Thanks



  • Hubman

    Hi,

    I have the exact same problem. My code is pretty much the same, the ScriptTransfer() does create the scripts but the tables are not created on the target servers in the target db. The db is created though; please advise.

    Thanks

    Nick


  • Aksi-

    I had it commented because the database was already created.

    I removed

    xfr.CopyAllTables = true; and left

    xfr.CopyAllObjects =
    true;



    It still doesnt work

    private void button1_Click(object sender, EventArgs e)

    {

    try {

    Server sv = new Server("ESTACION15");

    Database db = sv.Databases["GescomDllo"];

    Database db2 = new Database(sv, "PRUEBA");

    Transfer xfr;

    xfr = new Transfer(db);

    xfr.DestinationServer = "ESTACION15";

    xfr.DestinationLogin = "gescom";

    xfr.DestinationPassword = "gescom";

    xfr.CopyAllObjects = true;

    xfr.Options.WithDependencies = true;

    xfr.Options.ContinueScriptingOnError = false;

    xfr.DestinationDatabase = "PRUEBA";

    //'Script the transfer. Alternatively, perform immediate data transfer with TransferData method.

    xfr.ScriptTransfer();

    }

    catch (Exception ex)

    {

    richTextBox1.Text = ex.Message;

    }

    }



  • NJC

    Thank you very much Peter, can you tell me please how can I get the script from the scripttransfer method

    I have a richtextbox on my application and I want the result of the script to be copied in that richtextbox.

    I will try in a few moments , maybe it was a bug of sql ctps or vs 2005 rc. and now I have Rtms
    Thanks



  • rmillerii

    Thank you, I appreciate your help. The code still gives error at the ExecuteNonQuery:

    "ExecuteNonQuery failed for Database 'TEST'. "

    InnerException {"Cannot find the user 'SZ875492', because it does not exist or you do not have permission.\r\nCREATE SCHEMA failed due to previous errors."} System.Exception {System.Data.SqlClient.SqlException}

    It is trying to import users which I don't want to. How I ignore users and their permission when generating schema

    Thanks
    Nick


  • Derek Moffett

    I have followed the above steps to copy the database from an existing database using

    ScriptTransfer

    and

    ExecuteNonQuery, I am getting an error " User or Role already exists in the current database ". Please help.



  • Pansailor_74

    "xfr.CopyAllTables = true;" is redundant as you already specify to copy all objects.

    You need to create the target database, so ensure "// db2.Create();" is not commented.

    If that still fails, try first ScriptTransfer() so that can verify whether a script is actually generated (debug, or print the StringCollection that is output).



  • This SMO transfer script doesnt transfer ?