Greetings,
I have an application running on SQL Server 2005 (64 bit edition). The website has no traffic, just some occasional testing by me.
I've noticed the user connections (performance counters > Sql Server General Statistics > User Connections) never drops below 40 after I run through my site a few times.
I *am* using SQLCacheDependencies pretty aggressively in certain areas using this function:
1 public static DataTable GetDataTable(string strSprocName, SqlParameter[] Params, object[] Values, string cacheKey)
2 {
3 SqlConnection conn = new SqlConnection();
4 SqlCommand cmd = new SqlCommand();
5 string isCacheEnabled = ConfigurationSettings.AppSettings["DataTableCaching"].ToString().ToLower();
6 bool cacheEnabled = isCacheEnabled == "false" ? false : true;
7
8 try
9 {
10 //first check the cache...
11 DataTable dt = new DataTable();
12 if (!string.IsNullOrEmpty(cacheKey))
13 {
14 //if it IS in the cache..grab it and return..
15 if (HttpRuntime.Cache[cacheKey] != null && cacheEnabled)
16 {
17 dt = (DataTable)HttpRuntime.Cache[cacheKey];
18 #if DEBUG
19 Utils.LogHere("SPROC Found " + cacheKey);
20 #endif
21 return dt;
22 }
23
24 conn.ConnectionString = _Connection;
25 cmd.CommandType = CommandType.StoredProcedure;
26 cmd.CommandText = strSprocName;
27 cmd.Connection = conn;
28 conn.Open();
29
30 for (int i = 0; i < Params.Length; i++)
31 {
32 cmd.Parameters.Add(Params[i]).Value = Values[i];
33 }
34 SqlDataAdapter adapter = new SqlDataAdapter(cmd);
35 if (cacheEnabled)
36 {
37 SqlCacheDependency scd = new SqlCacheDependency(cmd);
38 adapter.Fill(dt);
39 adapter.Dispose();
40
41 //insert it into the chache
42 if (dt.Rows.Count > 0 && cacheEnabled)
43 {
44 HttpRuntime.Cache.Insert(cacheKey, dt, scd);
45 #if DEBUG
46 Utils.LogHere("SPROC Inserted " + cacheKey);
47 #endif
48 }
49
50 }
51 else
52 {
53 adapter.Fill(dt);
54 adapter.Dispose();
55 }
56
57 return dt;
58 }
59 else
60 {
61 throw new Exception("Cache key required");
62 }
63 }
64 catch (Exception ex)
65 {
66 throw ex;
67 //HttpContext.Current.Response.Redirect("Error.aspx");
68 //return null;
69 }
70 finally
71 {
72 cmd.Dispose();
73 conn.Close();
74 conn.Dispose();
75 }
76 }
77 I'm wondering if for every depdency I create, does a separate user connection get created and held open until the server restarts?
Does anyone know of any good resources I can read up on user connections, I can't seem to find much information in what are acceptable values
Is there anything else I should be doing with my SqlCacheDependencies? Do I have to put anything in my Application_End event to close them off?