Inquiridor
Erro : New transaction is not allowed because there are other threads running in the session.

Pergunta
-
Boa noite pessoal,
Estou enfrentando o seguinte problema estou tentando fazer um update no status do cliente, para alterar de Ativo para Inativo e vice-versa, acontece que quando chega no contexto.SaveChanges(); ele da essa mensagem de erro: oque pode ser ? já tentei fechar a conexao antes de salvar mas não consegui nada parecido na internet.
Server Error in '/' Application.
New transaction is not allowed because there are other threads running in the session.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: New transaction is not allowed because there are other threads running in the session.
Source Error:Line 348: { Line 349: item.status_Ativo_Inativo = 2; Line 350: contexto.SaveChanges(); Line 351: Line 352:
______________________________________________________________________
Segue o meu codigo;
public void EditarStatusCliente(Cliente cliente)
{
using (testeEntities contexto = new testeEntities())
{
var retornaObjeto = contexto.Status_Usuario_Fornecedor.Where(c => c.id_status == cliente.id_cliente);
foreach (var item in retornaObjeto)
{
if (item.status_Ativo_Inativo == 1)
{
item.status_Ativo_Inativo = 2;
contexto.SaveChanges();
}
else if (item.status_Ativo_Inativo == 2)
{
item.status_Ativo_Inativo = 1;
contexto.SaveChanges();
}
}
}
- Editado Alexandre1000a sexta-feira, 20 de setembro de 2013 22:21
Todas as Respostas
-
Alexandre,
Tente assim:
public void EditarStatusCliente(Cliente cliente)
{
using (testeEntities contexto = new testeEntities())
{
var retornaObjeto = contexto.Status_Usuario_Fornecedor.Where(c => c.id_status == cliente.id_cliente);
foreach (var item in retornaObjeto)
{
if (item.status_Ativo_Inativo == 1)
{
item.status_Ativo_Inativo = 2;
}
else if (item.status_Ativo_Inativo == 2)
{
item.status_Ativo_Inativo = 1;
}
}
contexto.SaveChanges();
}
Ricardo Minoru Makiyama
- Editado RMinoru segunda-feira, 23 de setembro de 2013 01:05
-
-