Create Login and Add User with SMO
-
Monday, November 14, 2005 2:57 PMBelow works great to add login to SQL Server 2005 but I cannot figure out how to add user to database in SMO. Any help would be greatly apprecitated.
Dim cn As New ServerConnectioncn.LoginSecure =
Falsecn.Login = gLogin
cn.Password = gPassword
cn.ServerInstance = gServer
cn.Connect()
Dim srv As Serversrv =
New Server(cn) Dim lg As Loginlg =
New Login(srv, strLogin)lg.DefaultDatabase = strDefDB
lg.LoginType = LoginType.SqlLogin
lg.Create(strPasswd)
All Replies
-
Wednesday, February 25, 2009 6:05 PMIf someone could finish this old thread it would be much appreciated :) I have the same problem
-
Thursday, April 16, 2009 7:33 AM
Here is how you create a login and a user that is associated/mapped to that login.
In VB.NET (converted with a translation tool)
In C#Dim server As New Server()
Dim loginName As String = "MyNewLogin"
Dim userName As String = "MyUserName"
Dim login As New Login(server, loginName)
login.LoginType = LoginType.SqlLogin
login.Create("password" )
Dim user As New User(server.Databases("dbName" ), userName)
user.Login = login.Name
user.Create()
Server server = new Server();
string loginName = "MyNewLogin";
string userName = "MyUserName";
Login login = new Login(server, loginName);
login.LoginType = LoginType.SqlLogin;
login.Create("password");
User user = new User(server.Databases["dbName"], userName);
user.Login = login.Name;
user.Create();
JH- Proposed As Answer by Michael Dent Friday, July 06, 2012 8:17 AM
-
Thursday, April 16, 2009 8:56 AMHi SpicyMikey,
Martin Xie has created a walkthrough on how to create a multi-users management program which the administrator can add and delete user accounts.
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/d6d593d0-bc13-410f-a0d3-126927ab6fbe
Thank you, msdn =) 99.9% of my questions have been answered :D

