Yes, I see the problem. You are not disposing of the connections because you
are returning from the methods before calling dispose on the connection
object. Remember, return immediately exits the method. Also, good
programming practice is to never have more than one return statement in your
method and it should always be the last statement in the method.
I posted the corrected code below.
Also, everyone else is right about opening and closing so many connections
so quickly. You should open the connection in the writeIDs method and pass
it as an argument to the other two methods. It will work the way I corrected
it below, but it would be much more efficient to open the connection once,
do ALL of your processing, then close the connection.
public void writeIDs()
{
StringBuilder sbsql = new StringBuilder();
//get array of ids we want to look at.
string[] filingIDs = getFilingIDs();
for(int i = 0;i < 50;i++)
{
string theseids = getIDs(Int32.Parse(filingIDs[i]));
if (theseids!= "0")
{
output(theseids.ToString());
}
}
}
public string getIDs(int filingid)
{
StringBuilder idlist = new StringBuilder();
string sql = "select thisid from holdings where thisid = "+ filingid;
string returnValue = null;
MySqlConnection myConn;
myConn = new
MySqlConnection(ConfigurationSettings.AppSettings["connString"]);
MySqlCommand myCommand = new MySqlCommand(sql, myConn);
myConn.Open();
MySqlDataReader dr = myCommand.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
if (dr["thisid"].ToString().Length > 0)
{
idlist.Append("'" + dr["thisid"].ToString()+"',");
}
}
}
int thislength= idlist.ToString().Length;
if (thislength> 0)
{
returnValue = idlist.ToString().Substring(0,thislength);
}
else
{
returnValue = "0";
}
if(myConn != null)
{
myConn.Close();
myConn.Dispose();
}
return returnValue;
}
public string[] getFilingIDs()
{
StringBuilder IDs = new StringBuilder();
string sql = "select filingid from filings where filing_type = 1 and
parseid > 0 limit 100 ";
MySqlConnection myConn = new
MySqlConnection(ConfigurationSettings.AppSettings["connString"]);
MySqlCommand myCommand = new MySqlCommand(sql, myConn);
myConn.Open();
MySqlDataReader dr = myCommand.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
IDs.Append(dr["filingid"].ToString()+",");
}
}
int filingIDLength = filingIDs.ToString().Length-1;
if(myConn != null)
{
myConn.Close();
myConn.Dispose();
}
return filingIDs.ToString().Substring(0,filingIDLength).S plit(',');
}
"Brent" <""b b i g l e r \"@ y a h o o . c o m"> wrote in message
news:11*************@corp.supernews.com...
Hmmm...tried that, with no luck...
The full code, which isn't much more, is here:
================================================== =
public void writeIDs()
{
StringBuilder sbsql = new StringBuilder();
//get array of ids we want to look at.
string[] filingIDs = getFilingIDs();
for(int i = 0;i < 50;i++)
{
string theseids = getIDs(Int32.Parse(filingIDs[i]));
if (theseids!= "0")
{
output(theseids.ToString());
}
}
}
public string getIDs(int filingid)
{
StringBuilder idlist = new StringBuilder();
string sql = "select thisid from holdings where thisid = "+ filingid;
MySqlConnection myConn;
myConn = new
MySqlConnection(ConfigurationSettings.AppSettings["connString"]);
MySqlCommand myCommand = new MySqlCommand(sql, myConn);
myConn.Open();
MySqlDataReader dr = myCommand.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
if (dr["thisid"].ToString().Length > 0)
{
idlist.Append("'" + dr["thisid"].ToString()+"',");
}
}
}
int thislength= idlist.ToString().Length;
if (thislength> 0)
{
return idlist.ToString().Substring(0,thislength);
}
else
{
return "0";
}
if(myConn != null){myConn.Close();myConn.Dispose();}
}
public string[] getFilingIDs()
{
StringBuilder IDs = new StringBuilder();
string sql = "select filingid from filings where filing_type = 1 and
parseid > 0 limit 100 ";
MySqlConnection myConn = new
MySqlConnection(ConfigurationSettings.AppSettings["connString"]);
MySqlCommand myCommand = new MySqlCommand(sql, myConn);
myConn.Open();
MySqlDataReader dr = myCommand.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
IDs.Append(dr["filingid"].ToString()+",");
}
}
int filingIDLength = filingIDs.ToString().Length-1;
return filingIDs.ToString().Substring(0,filingIDLength).S plit(',');
if(myConn != null){myConn.Close();myConn.Dispose();}
}
===========================
Andrew Robinson wrote: Kind of an incomplete code snippet, but how about closing your
connection before you dispose it?