Page 1 of 1

EntityFramework SET ROLE How to

Posted: Fri 28 Aug 2009 08:53
by HCRoman
Hi experts,

i want to use

SET ROLL APP_ROLE;

during Connection_StateChange event.

I tryed:

private void Connection_StateChange(object sender, System.Data.StateChangeEventArgs e)
{

if (e.CurrentState == System.Data.ConnectionState.Open)
{
DbConnection conn = sender as DbConnection;
int result = 0;
using (DbCommand command = conn.CreateCommand())
{
command.CommandText = "SET ROLE APP_ADMIN";
result = command.ExecuteNonQuery();
}
}

But I get an EntitySqlException Sql Statement error near ID ROLE

Is it not possible to do this for a connection or missed i something??.


Question is, how to set a role as the first action after the connection opens?


Thanks

Roman

Posted: Mon 31 Aug 2009 08:41
by Shalex
Please replace this line of your code

Code: Select all

DbConnection conn = sender as DbConnection;
with the following

Code: Select all

DbConnection conn = (sender as EntityConnection).StoreConnection;

Posted: Mon 31 Aug 2009 10:53
by HCRoman
Thanks,

its now clear... :idea: