EntityFramework SET ROLE How to

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
HCRoman
Posts: 55
Joined: Wed 12 Aug 2009 05:47

EntityFramework SET ROLE How to

Post by HCRoman » Fri 28 Aug 2009 08:53

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

Shalex
Site Admin
Posts: 8240
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Mon 31 Aug 2009 08:41

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;

HCRoman
Posts: 55
Joined: Wed 12 Aug 2009 05:47

Post by HCRoman » Mon 31 Aug 2009 10:53

Thanks,

its now clear... :idea:

Post Reply