Skip to content

Instantly share code, notes, and snippets.

@leppie
Created July 2, 2016 09:04
Show Gist options
  • Select an option

  • Save leppie/342ff55d2a6c0bbef2fd2047bdfb4aaf to your computer and use it in GitHub Desktop.

Select an option

Save leppie/342ff55d2a6c0bbef2fd2047bdfb4aaf to your computer and use it in GitHub Desktop.
public static SqlConnection Connection
{
get
{
var ctx = HttpContext.Current;
var con = (SqlConnection) ctx.Items["Connection"];
if (con == null)
{
ctx.Items["Connection"] = con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
ctx.AddOnRequestCompleted(_ => con.Dispose());
}
return con;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment