.NET 4.0 Chart Control Problem – Connection Was Not Closed
So, I’ve go this huge perfmon log file that I’m trying to get some charts out of and excel just isn’t cutting it for me and SSRS just turned out to be a pain and no easier than making my own app (learning curve) so here I am, making a basic charting program in C#. As you may have noticed I spend most of my time in Powershell so I’m stumbling over this a bit and I ran in to a problem using the charting control that is telling me the connection was not closed when I attempt to bind my SQLCommand object to the chart control. Come to find out the connection needs to be closed and the chart needs to open it.
here is some sample code:
string query = "select field1, field2 from table";
string connstr = "Server=yourserver;Database=yourdb;integrated security";
SqlConnection conn = new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand(query, conn);
chart1.DataSource = cmd;
chart1.Series["Series1"].XValueMember = "field1";
chart1.Series["Series1"].YValueMembers = "field2";
catch (Exception Ex)
As you’ll notice, no where do you open or close the connection, its handled by the chart. Seems a little weird to me, but I guess that’s cool.