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

[177 byte] By [eric_c007] at [2008-2-18]
# 1
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
PeterSaddowMSFT at 2007-10-6 > top of Msdn Tech,SQL Server,SQL Server SMO/DMO...
# 2
Note that you cannot use VBScript as SMO does not expose a comprehensive set of COM wrappers. See this posting as well: http://blogs.msdn.com/mwories/articles/smofaq.aspx
MichielWories at 2007-10-6 > top of Msdn Tech,SQL Server,SQL Server SMO/DMO...

SQL Server

Site Classified