Jason This is actually quite a subtle one, but the problem is because the connection is closed with CommandBehavior.CloseConnection only when the datareader is closed (which isn't happening in this case). So, you've either got to call dr.Close, or remove the call to CommandBehavior and close the connection explicitly. Hint, try this:
using (SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionStringUSR"]))
{
... Do the other database work here...
}
or
SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
try
{
if(dr.Read()==true)
{
if(dr.IsDBNull(0))
return -1;
else
return dr.GetInt32(0);
}
else
{
return -1;
}
}
finally
{
dr.Close();
}
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.