sql server 2012 express - How to activate application roles using typed dataset in C#? -
i working in windows c# 2013 project has sql server 2012 express database, have created 3 application roles, use typed dataset in project, search way activate application role in project.
i found information not complete answers, made code not working, because event connection_statechange not fire, here code in class class1 in project put code:
public string rl, rlpss; //rl, rlpss variables contain role name , password. public void setapprole(sqlconnection ta) { if (ta.state==connectionstate.open) { ta.close(); } ta.open(); ta.statechange += connection_statechange; } void connection_statechange(object sender, statechangeeventargs e) { if (e.originalstate==system.data.connectionstate.closed && e.currentstate==system.data.connectionstate.open) { system.data.sqlclient.sqlcommand scm = new sqlcommand(); scm.connection = (sqlconnection)sender; scm.commandtext = "exec sp_setapprole '" + rl + "' , '" + rlpss + "'"; scm.executenonquery(); } }
in login under btnlogin
put code:
cl.setapprole((system.data.sqlclient.sqlconnection)tableadaptermanager.connection); mdiparent1 md = new mdiparent1(); md.show();
i passed role name , password rl, rlpss.
i followed execution of code , found event connection_statechange not fired.
register event before change state
public void setapprole(sqlconnection ta public void setapprole(sqlconnection ta) { ta.statechange += connection_statechange; if (ta.state==connectionstate.open) { ta.close(); } ta.open(); }