c# - “error: 19 - Physical connection is not usable” with OWIN access in Azure database -


i have tried other postings on dreaded "error 19" , found few answers not apply or not help, hence new post. serious potential problem azure+ef users.

first occurrence:

i using latest version of in vs2013 ef6.1 razor project (packages listed @ end). database hosted on sql azure.

after running webapp few time (in dev environment) error: a transport-level error has occurred when receiving results server. (provider: session provider, error: 19 - physical connection not usable)

the line dies on this: enter image description here

i gather error relates connection pooling (and running out of connections), cannot spot leak anywhere.

as access owin membership , other database features throughout app have databasecontoller other controllers inherit. creates relevant components , disposes of them.

databasecontroller.cs

[authorize] public class databasecontroller : controller {     #region properties     /// <summary>     /// user manager - attached application db context     /// </summary>     protected usermanager<applicationuser> usermanager { get; set; }      /// <summary>     /// role manager - attached application db context     /// </summary>     protected rolemanager<identityrole> rolemanager { get; set; }      /// <summary>     /// application db context     /// </summary>     protected applicationdbcontext applicationdbcontext { get; set; }      /// <summary>     /// database context used controllers     /// </summary>     protected applicationentities context { get; set; }     #endregion properties      #region constructors     public databasecontroller()     {         this.context = new applicationentities ();         this.applicationdbcontext = new applicationdbcontext();         this.usermanager = new usermanager<applicationuser>(new userstore<applicationuser>(this.applicationdbcontext));         this.rolemanager = new rolemanager<identityrole>(new rolestore<identityrole>(this.applicationdbcontext));         this.usermanager.uservalidator = new uservalidator<applicationuser>(usermanager) { allowonlyalphanumericusernames = false };     }     #endregion constructors      protected override void dispose(bool disposing)     {         if (disposing)         {             if (usermanager != null)             {                 this.usermanager.dispose();                 this.usermanager = null;             }             if (this.rolemanager != null)             {                 this.rolemanager.dispose();                 this.rolemanager = null;             }             if (this.applicationdbcontext != null)             {                 this.applicationdbcontext.dispose();                 this.applicationdbcontext = null;             }             if (this.context != null)             {                 this.context.dispose();                 this.context = null;             }         }         base.dispose(disposing);     } } 

packages installed

  <package id="antlr" version="3.5.0.2" targetframework="net45" />   <package id="bootstrap" version="3.1.1" targetframework="net45" />   <package id="entityframework" version="6.1.0" targetframework="net45" />   <package id="jquery" version="1.11.0" targetframework="net45" />   <package id="jquery.validation" version="1.11.1" targetframework="net45" />   <package id="json2" version="1.0.2" targetframework="net45" />   <package id="microsoft.aspnet.identity.core" version="2.0.0" targetframework="net45" />   <package id="microsoft.aspnet.identity.entityframework" version="2.0.0" targetframework="net45" />   <package id="microsoft.aspnet.identity.owin" version="2.0.0" targetframework="net45" />   <package id="microsoft.aspnet.mvc" version="5.1.1" targetframework="net45" />   <package id="microsoft.aspnet.razor" version="3.1.2" targetframework="net45" />   <package id="microsoft.aspnet.web.optimization" version="1.1.3" targetframework="net45" />   <package id="microsoft.aspnet.webapi" version="5.1.2" targetframework="net45" />   <package id="microsoft.aspnet.webapi.client" version="5.1.2" targetframework="net45" />   <package id="microsoft.aspnet.webapi.core" version="5.1.2" targetframework="net45" />   <package id="microsoft.aspnet.webapi.webhost" version="5.1.2" targetframework="net45" />   <package id="microsoft.aspnet.webpages" version="3.1.2" targetframework="net45" />   <package id="microsoft.jquery.unobtrusive.validation" version="3.1.2" targetframework="net45" />   <package id="microsoft.owin" version="2.1.0" targetframework="net45" />   <package id="microsoft.owin.host.systemweb" version="2.1.0" targetframework="net45" />   <package id="microsoft.owin.security" version="2.1.0" targetframework="net45" />   <package id="microsoft.owin.security.cookies" version="2.1.0" targetframework="net45" />   <package id="microsoft.owin.security.facebook" version="2.1.0" targetframework="net45" />   <package id="microsoft.owin.security.google" version="2.1.0" targetframework="net45" />   <package id="microsoft.owin.security.microsoftaccount" version="2.1.0" targetframework="net45" />   <package id="microsoft.owin.security.oauth" version="2.1.0" targetframework="net45" />   <package id="microsoft.owin.security.twitter" version="2.1.0" targetframework="net45" />   <package id="microsoft.web.infrastructure" version="1.0.0.0" targetframework="net45" />   <package id="modernizr" version="2.7.2" targetframework="net45" />   <package id="newtonsoft.json" version="6.0.2" targetframework="net45" />   <package id="owin" version="1.0" targetframework="net45" />   <package id="owin.security.providers" version="1.3.1" targetframework="net45" />   <package id="respond" version="1.4.2" targetframework="net45" />   <package id="webgrease" version="1.6.0" targetframework="net45" /> 

assuming connection leak, how can track down source of leak?

if need more information, ask.

update: 22 may 2014 second bounty offered

i still have same problem, slight project changes made since last posting, post latest details below shortly.

i have added connection lifetime=3;max pool size=3; connection strings, based on this post.

update: 23 may 2014 error still occurs

the next day, after debugging few dozen times, error returned.

update: 11 june 2014

after 2 bounties , countless google investigations (no real answer this), have assume flaw in entity framework 6, somehow causing appear.

more information:

i had same error in winform project, connect azure. in instance accidentally not clearing entity list after each 20 new items added.

every time code ran added 20 more records , updated datemodified field on of them. time hit 1700 records being updated gave dreaded "error 19 - physical connection not usable". after needed restart debug iis work @ all.

obviously code had run massive number of updates, , maybe someone think of something.

error 19 not comms error! (or not comms error)

just ensure have required .include(x=>x.foreigntable) calls in linq sql query!

updated aug 2015 (possible solution for, at least, scenarios):

we had 100% repro case on problem, able resolve trial , error testing, may solution or @ least provide clues on for.

scenario:

  • the error occurred under release builds running under iis. did not occur under debug or under iis express.
  • we turned on sql profiling see when/where server hit.
  • the query in question fetching matching records, creating view-models in foreach iteration of results (ie. lazy evaluation). view-model dependant on value in related table of queried entity.

testing:

first attempt: remove complex filters on query

  • result: still failed error 19

second attempt: add tolist() query force query to run completion immediately.

  • result: successful!!! (obviously going on here)

third attempt: remove tolist() , add .include(x=>x.foreigntable) query force inclusion of related data.

  • result: success!

my new theory is:

if accidentally leave out include of foreign table, ef randomly fail fetch related data when lazily-evaluating. can lead infamous error 19.

as there foreign-key relationships in identify framework, might assume there missing .include(), or equivalent, on query somewhere within owin. might causing random problem when using owin or other queries.

notes:

  • a key point take away error 19 not comms error. queries hit sql server. problem client-side failing fetch related data.

pause applause (we happy have found this) :)

updated 28 august 2015:

just had dreaded error 19 again today, connecting local sql database (usually problem azure me). based on results above added .include(x=>x.foreigntable) statement appropriate , problem vanished! seem problem of ef not being able lazy-load related-table information.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -