I'm thinking it's this:
} finally {
dt = null;
(Experimentation has ruled that out.)
Let's try to simplify your code then -- and use
using
statements as well.
DataTable dt = null ;
using ( SqlCommand cmd = conn.CreateCommand() )
{
cmd.commandtext = "Select * from users WHERE [Name]=@UserName AND [Pwd]=@Password";
cmd.Parameters.AddWithValue("@UserName" , "ادمین" ) ;
cmd.Parameters.AddWithValue("@Password" , "ادمین" ) ;
if (conn.State == ConnectionState.Closed) conn.Open();
using ( SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection) )
{
dt = new DataTable("temp");
dt.Load(dr);
}
}
return dt;
You'll notice I also removed the try/catch, you can add one back in if you need to.