SMO Script Method
Does anybody have any detailed information on the SMO script method? I am trying to write a VBScript that will script the logins on a SQL 2005 server.
Thanks!
Eric
You can not use VBScript to call SMO. But you can do the following through C#:
static void Main(string[] args)
{
Server srv = new Server("MyServer"); //Yukon
srv.ConnectionContext.LoginSecure = true;
srv.ConnectionContext.Connect();
srv.DefaultTextMode = false;
try
{
Database db = srv.Databases["customer"];
Transfer trans = new Transfer(db);
trans.Options.IncludeIfNotExists = true;
trans.CopyAllObjects = false;
trans.CopyAllLogins = true;System.Collections.Specialized.
StringCollection script = new StringCollection();script = trans.ScriptTransfer();
foreach (String str in script)
{
Console.WriteLine("GO");
Console.WriteLine(str);
}
}catch (Exception ex){
Console.WriteLine(ex);}
Peter