I have this problem. I've googled a lot of sites with this issue, but all of them advice to close all the connection, or just using "using" with connection and dataReader. BUT! My probles is in that I can't open the first connection! I set a breakpoint near connection, and saw, that there are no others connections, so, there is a first one. This problem rized when I remake the class which open connection from static to Singleton, here is the code:
public class Storage
{
private static Storage instance;
public static Storage Instance
{
get
{
if (instance == null)
{
instance = new Storage();
}
return instance;
}
}
private Storage()
{
Manager man = new Manager();
products = man.LoadProducts();
components = man.LoadComponents();
man.LoadProductComponents();
}
public Dictionary<int, Product> Products
{
get { return products; }
set { products = value; }
}
public Dictionary<int, Component> Components
{
get { return components; }
set { components = value; }
}
private Dictionary<int, Product> products;
private Dictionary<int, Component> components;
}
and here is a Manager constructor
public Manager()
{
connection = new SqlConnection(@"Persist Security Info=False;User ID=user;Password=pass;Initial Catalog=Products;Server=(local)");
if (connection.State != ConnectionState.Open) connection.Open();
}
When exception raises, the connection is Closed
. Any one have ideas?
UPDATE:
if I turn off pooling - I have "System.StackOverflowException" in System.Data.dll
at the same line.