Dear All
Is there any sample code which creates login and user for database using SMO?I cannot find any C# sample code can do this.
Any help would be appreciated:)
Here's a sample, you can build from it to allow for creation of group or other login types, etc.
Set up connection to server and database:
_srv = new Server(@."MySqlServer\Instancename");
_dbname = @."MyDatabase";
_db = _srv.Databases[ DBName];
Login lgn = new Login(_srv, @."domain\username");
lgn.DefaultDatabase = _dbname;
lgn.LoginType = LoginType.WindowsUser;
lgn.Create();
User usr = new User(_db, @."MyUserName");
usr.Login = loginId;
usr.Create();
--Stan
|||My bad, I was reading this topic in reverse date order and just noticed that another thread asked a similar question and got basically the same response.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=195387&SiteID=1
|||Hi,
sorry the same day you posted the question I wrote quick application, I imported that in a q&d Winform solution, which might help you to see the way to do it:
http://www.sqlserver2005.de/SharedFiles/UserMappingwithSMO.zip
HTH; Jens Suessmeyer.
http://www.sqlserver2005.de
No comments:
Post a Comment