Database abstraction class in C# (version 2) Below is my revised version of this code after I acted on the suggestions:

Database abstraction class in C#

class DatabaseAccess : IDisposable
{
    private SqlConnection connection;
    private SqlCommand alreadyDownloadedCommand;
    private SqlCommand markedDownloadedCommand;
    // *FieldSize variables match the size of the field in the database.
    private const int FileNameFieldSize = 80;
    private const int AppTypeFieldSize = 2;
    private const int UserNameFieldSize = 8;

    public DatabaseAccess(string dbconnectionstring)
    {
        connection = new SqlConnection(dbconnectionstring);

        connection.Open();
        alreadyDownloadedCommand = getAlreadyDownloadedCommand(connection);
        markedDownloadedCommand = getMarkedDownloadedCommand(connection);
    }

    public void Dispose()
    {
        alreadyDownloadedCommand.Dispose();
        markedDownloadedCommand.Dispose();
        connection.Dispose();
    }
    private void ValidateFieldSize(string fielddata, int fieldsize)
    {
        if (fielddata.Length &gt; fieldsize)
        {
            throw new ArgumentOutOfRangeException("Parameter size too large");
        }
    }
    private SqlCommand getMarkedDownloadedCommand(SqlConnection connection)
    {
        const string sql =
        @"insert into dbo.InspectionsDownloaded(FileName)
          values (@FileName)
        ";
        SqlCommand command = new SqlCommand(sql, connection);
        command.Parameters.Add(new SqlParameter("@FileName", System.Data.SqlDbType.VarChar, FileNameFieldSize));
        command.Prepare();
        return command;
    }

    private SqlCommand getAlreadyDownloadedCommand(SqlConnection connection)
    {
        const string sql =
        @"select count(*) as numDownloaded
            from dbo.InspectionsDownloaded id
           where id.FileName = @FileName
        ";
        SqlCommand command = new SqlCommand(sql, connection);
        command.Parameters.Add(new SqlParameter("@FileName", System.Data.SqlDbType.VarChar, FileNameFieldSize));
        command.Prepare();
        return command;
    }
    public bool IsAlreadyDownloaded(string filename)
    {
        int rowCount;
        ValidateFieldSize(filename, FileNameFieldSize);
        alreadyDownloadedCommand.Parameters[0].Value = filename;
        rowCount = (Int32)alreadyDownloadedCommand.ExecuteScalar();
        return (rowCount != 0);
    }
    public int MarkDownloaded(string filename)
    {
        ValidateFieldSize(filename, FileNameFieldSize);
        markedDownloadedCommand.Parameters[0].Value = filename;
        return(markedDownloadedCommand.ExecuteNonQuery());
    }
}
Some organization nitpicks first :


Your class file should start with the const
Even your private functions should be PascalCased meaning getAlreadyDownloadedCommand should be GetAlreadyDownloadedCommand
Your public methods should appear before your private methods IMO


You don't implement the Dispose pattern correctly. You should check this article but basically, to properly dispose your object, the pattern is the following :

public void Dispose()
{  
    Dispose(true);  
    GC.SuppressFinalize(this);  
}  

protected virtual void Dispose(bool disposing)
{  
    if (disposing){  
        if (connection != null) connection.Dispose();  
        //etc.
    }  
}  


I must say I'm not 100% why we need to do it this way, but this is how it is supposed to be implemented according to Microsoft's documentation and developer tools like Resharper.

When you have a public method/constructor/etc, you should always check your input for null. Don't trust the user of your code, even if it's yourself! If you check your inputs for null, you'll know very fast if your input is null, instead of having a weird exception that tells you little to nothing.

public DatabaseAccess(string dbconnectionstring)
{
    if(String.IsNullOrWhitespace(dbconnectionstring) throw new ArgumentNullException(nameof(dbconnectionstring));

    connection = new SqlConnection(dbconnectionstring);

    connection.Open();
    alreadyDownloadedCommand = getAlreadyDownloadedCommand(connection);
    markedDownloadedCommand = getMarkedDownloadedCommand(connection);
}