// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Text; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Smo; namespace E { public class Program { public static void Main(string[] args) { Server srv = new Server(@"ARNEPC3\SQLEXPRESS"); srv.ConnectionContext.LoginSecure = true; srv.ConnectionContext.Connect(); Transfer t = new Transfer(srv.Databases["Test"]); t.CopyAllObjects = true; t.CopyData = true; // does not work StringBuilder sb = new StringBuilder(); foreach (string s in t.ScriptTransfer()) { sb.Append(s); sb.Append(Environment.NewLine); } string res = sb.ToString(); srv.ConnectionContext.Disconnect(); Console.WriteLine(res); } } }