using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlCon;
sqlCommand.CommandType = CommandType.Text;
sqlCommand.CommandText = "EXEC sp_setapprole 'application Role name','password';";
sqlCommand.CommandText += sqlComm;
sqlCommand.CommandTimeout = 300;
sqlCon.Open();
int res = sqlCommand.ExecuteNonQuery();
}
This code is in a loop. for the first time, it's OK. In second iterator, it throws exception.After a SQL Server application role has been activated by calling the sp_setapprole system stored procedure, the security context of that connection cannot be reset. However, if pooling is enabled, the connection is returned to the pool, and an error occurs when the pooled connection is reused.
{
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlCon;
sqlCommand.CommandType = CommandType.Text;
sqlCommand.CommandText = "EXEC sp_setapprole 'application Role name','password';";
sqlCommand.CommandText += sqlComm;
sqlCommand.CommandTimeout = 300;
sqlCon.Open();
int res = sqlCommand.ExecuteNonQuery();
}
This code is in a loop. for the first time, it's OK. In second iterator, it throws exception.
If you are using SQL Server application roles, we recommend that you disable connection pooling for your application in the connection string.
Pooling can be disabled for the SQL Server .Net Data Provider by adding "Pooling=False" to the connection string.
Reference Links:http://support.microsoft.com/default.aspx?scid=kb;en-us;q229564
No comments:
Post a Comment