In DMO the server object had an add method on the Logins collection. Does anyone know how this works in SMO the logins collection does not have an add.
I have spent hours on this and just cannot figure out how to create a new login on a server using SMO. I guess I could allways script the login but there must ba a way to do this in SMO.
Thanks
You can create a login as follows:
Server srv = new Server("MyServer"); //Yukon
srv.ConnectionContext.LoginSecure = true;
srv.ConnectionContext.Connect();
srv.DefaultTextMode = false;
string lgName = "MyNewLogin";
if (srv.Logins[lgName] == null)
{
Login lg = new Login(srv, lgName);
lg.LoginType = LoginType.SqlLogin;
lg.Create("MyPassword!#");
}
Peter
No comments:
Post a Comment