I have a break from Npgsql 2.2.4.3 to 2.2.5 in my current project. The error below was triggered when I try to create a new database having a Entity Framework context in use on the same Postgre server (but a different database).
...
This code works fine with any version of Npgsql from 2.2.2 to 2.2.4.3 (not tested before 2.2.2, but should works too and avoid the 2.2.4.1 because Npgsql.EntityFramework) and with any version of Entity Framework from 6.0.0 to 6.1.3 (I have tested the permutations to be sure).
If I pause the execution after the first use of DbMaster (the Any() query) and try to create a database with pgAdminIII in the same server I also get this error.
Message: ERROR: 55006: source database "template1" is being accessed by other users
em Npgsql.NpgsqlState.<ProcessBackendResponses>d__0.MoveNext()
em Npgsql.ForwardsOnlyDataReader.GetNextResponseObject(Boolean cleanup)
em Npgsql.ForwardsOnlyDataReader.GetNextRowDescription()
em Npgsql.ForwardsOnlyDataReader.NextResultInternal()
em Npgsql.ForwardsOnlyDataReader..ctor(IEnumerable`1 dataEnumeration, CommandBehavior behavior, NpgsqlCommand command, NotificationThreadBlock threadBlock, Boolean preparedStatement, NpgsqlRowDescription rowDescription)
em Npgsql.NpgsqlCommand.GetReader(CommandBehavior cb)
em Npgsql.NpgsqlCommand.ExecuteNonQuery()
em Hgm.Gestao.Infraestrutura.BancoDados.BancoDadosHelper.CriarBdn(String sbdn, String bdn) na c:\Users\Max\Documents\Visual Studio 2013\Projects\GestaoWeb-v1a\Infraestrutura\BancoDados\BancoDadosHelper.cs:linha 46
em Hgm.Gestao.Infraestrutura.BancoDados.BancoDadosHelper.CriarBdnSeNaoExistir(String sbdn, String bdn) na c:\Users\Max\Documents\Visual Studio 2013\Projects\GestaoWeb-v1a\Infraestrutura\BancoDados\BancoDadosHelper.cs:linha 31
em Hgm.Gestao.Servicos.Principal.ContaServico.CriarEmpresaModeloNegocioSeNaoExistir(Guid empresaMestreId) na c:\Users\Max\Documents\Visual Studio 2013\Projects\GestaoWeb-v1a\Servicos\Principal\ContaServico.cs:linha 161
em Hgm.Gestao.Web.Controllers.ContaController.SessaoUsuarioEmpresa(Guid empresaMestreId) na c:\Users\Max\Documents\Visual Studio 2013\Projects\GestaoWeb-v1a\Web\Controllers\ContaController.cs:linha 94
em lambda_method(Closure , ControllerBase , Object[] )
em System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
em System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
em System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
em System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod()
em System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
em System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
em System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
em System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
em System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
em System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
em System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()