O'Reilly logo

.NET Framework 4.5 Expert Programming Cookbook by A.P. Rajshekhar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Managing connections manually for long-running tasks

Entity Framework manages connections by itself. In other words, you as a developer need not open and close connections manually. However, there are scenarios where you would want to manage the opening and closing of connections manually. Saving large-sized files to a database is one such scenario.

In this recipe, we will look at the steps required in managing connections manually. To do so, we will use the application developed in the previous recipe.

How to do it...

  1. Open FileUpload.sln in Visual Studio 2012.
  2. Open UploadForm.cs in the view code mode.
  3. In the btnUpload_Click method, replace the using statement with the following statement:
    CookBookEntities context = new CookBookEntities();
  4. Next, add ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required