Try Disposing your connections (and your commands, etc.) that may well dispose of your problem!
The easiest way is to use a
using
block:
using (MySqlConnection con = new MySqlConnection(strCon))
{
con.Open();
using (MySqlCommand ver = new MySqlCommand("SELECT MAX(version) FROM dlContent WHERE fileName=@FN", con))
{
ver.Parameters.AddWithValue("@FN", filename);
object o = ver.ExecuteScalar();
if (o != null && o != System.DBNull.Value)
{
version = (int) o + 1;
}
}
using (MySqlCommand ins = new MySqlCommand("INSERT INTO dlContent (iD, fileName, description, dataContent, version) " +
"VALUES (@ID, @FN, @DS, @DT, @VS)", con))
{
ins.Parameters.AddWithValue("@ID", Guid.NewGuid());
ins.Parameters.AddWithValue("@FN", filename);
ins.Parameters.AddWithValue("@DS", "");
ins.Parameters.AddWithValue("@DT", filedata);
ins.Parameters.AddWithValue("@VS", version);
ins.ExecuteNonQuery();
}
}
Won't help - it comes direct from my Web.Config (redacted version):
<connectionstrings>
<add name="LoginDatabase" connectionstring="Database=mydatabase;Data Source=localhost;User Id=XXXX;Password=XXXX"></add>
<add name="LocalMySqlServer" connectionstring="server=localhost;database=XXXX;uid=XXXX;pwd=XXXX" providername="MySql.Data.MySqlClient"></add>
</connectionstrings>