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 ServerConnection
cn.Login = gLogin
cn.Password = gPassword
cn.ServerInstance = gServer
cn.Connect()Dim srv As Server
srv =New Server(cn) Dim lg As Login
lg =New Login(srv, strLogin)
lg.DefaultDatabase = strDefDB
lg.LoginType = LoginType.SqlLogin
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 AMHere is how you create a login and a user that is associated/mapped to that login.
In VB.NET (converted with a translation tool)
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
Dim user As New User(server.Databases("dbName" ), userName)
user.Login = login.Name
Server server = new Server();
string loginName = "MyNewLogin";
string userName = "MyUserName";
Login login = new Login(server, loginName);
login.LoginType = LoginType.SqlLogin;
User user = new User(server.Databases["dbName"], userName);
user.Login = login.Name;
- 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.
Thank you, msdn =) 99.9% of my questions have been answered :D