How to create new SQL Server 2008 R2 login using C# -
i using visual studio 2012 , c#
i use below code create login , user sql server database using c#
it works sql server 2012 doesn't work on sql server 2008 r2.
here's code:
var servername = "."; // sql server instance name var databasename = "test"; // database name var loginname = "testusery"; // login name (should not exist - or should add code check if login exists) server svr = new server(servername); var db = svr.databases[databasename]; if (db != null) { login login = new login(svr, loginname); login.defaultdatabase = "master"; // logins typically have master default database login.logintype = logintype.sqllogin; login.create("foobar", logincreateoptions.none); // enter suitable password login.enable(); user user = new user(db, loginname); user.usertype = usertype.sqllogin; user.login = login.name; user.create(); user.addtorole("db_owner"); server svr = new server(servername);
this code , other code after doesn't run in sql server 2008 r2.
help me please.
i found problem. solve problem should copy dlls in app folders: microsoft.sqlserver.connectioninfo.dll
microsoft.sqlserver.management.sdk.sfc.dll
microsoft.sqlserver.smo.dll
microsoft.sqlserver.sqlclrprovider.dll
microsoft.sqlserver.sqlenum.dll
Comments
Post a Comment