I do not use LINQ-to-SQL or Entity Framework bits in a web application and currently use something like this (this is for a class project):
using System.Data; using System.Data.SqlClient; namespace StackOverflowClone.Models { public class Database { public static SqlConnection ActiveConnection { get; private set; } static Database() { ActiveConnection = new SqlConnection( "Data Source=********.database.windows.net;" + "Initial Catalog=EECS341;Uid=*****;Pwd=*******;" + "MultipleActiveResultSets=True;"); ActiveConnection.Open(); } } }
However, this seems to cause threading problems, since the static initializer is run once per server process, and not once per request.
Does the infrastructure provide a built-in method for handling this, or should I have a function that rewinds database connections each time?
Billy oneal
source share