Question: My program loads data from a MySQL database into a `DataGridView`. I want to hide the first column (`id` column), but I get the reentrance cell error.

CODE:

```
void dataGridGlavni_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e)
    {
        if (this.dataGridGlavni.Columns[e.ColumnIndex].Name == "id")
        {
            this.dataGridGlavni.Columns[e.ColumnIndex].Visible = false; // <<<< error
        }
        if (this.dataGridGlavni.Columns[e.ColumnIndex].Name == "Plate za mesec")
        {
            GlavniForm.ShortFormDateFormat(e);
        }
    }

```

ERROR:

> 
> Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.
> 
> 
> 

The error also appears when I use the following line:

```
this.dataGridGlavni.Columns[0].Visible = false;

```

However it does NOT appear when I use these lines:

```
this.dataGridGlavni.Columns[1].Visible = false;

```

OR

```
this.dataGridGlavni.Columns["Plate za mesec"].Visible = false;

```

I googled a lot and haven't been able to find the source of the error. What is happening why won't it let me hide the first column ?

Thank you

Answer: 
There are already a lot of great answers here but it's worth mentioning a simple and quick way to get the **SQL Server Database size with SQL Server Management Studio (SSMS)** using a standard report. 

To run a report you need:

1. right-click on the database
2. go to Reports > Standard Reports > Disk Usage.

It prints a nice report:

[![enter image description here](https://i.stack.imgur.com/joGAd.png)](https://i.stack.imgur.com/joGAd.png)

Where the **Total space Reserved** is the total size of the database on the disk and it includes the size of all data files and the size of all transaction log files.

Under the hood, SSMS uses [dbo.sysfiles](https://learn.microsoft.com/en-us/sql/relational-databases/system-compatibility-views/sys-sysfiles-transact-sql?view=sql-server-ver15) view or [sys.database\_files](https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-database-files-transact-sql?view=sql-server-ver15) view (depending on the version of MSSQL) and some kind of this query to get the Total space Reserved value:

```
SELECT sum((convert(dec (19, 2),  
convert(bigint,SIZE))) * 8192 / 1048576.0) db_size_mb
FROM dbo.sysfiles;

```
If you would like to get size of real data, you'll need to filter 'ONLINE' data files only. Otherwise you can get a size that significately different from the size you see in GUI. Some ghost | old garbage records can be in the sys.master\_files, for example 'DEFUNCT' data files.

```
    with fs
    as
    (
        select database_id, type, size * 8.0 / 1024 size, physical_name
        from sys.master_files
        where state_desc = 'ONLINE' -- ONLINE,RESTORING,RECOVERING,RECOVERY_PENDING,SUSPECT,,OFFLINE, DEFUNCT
    )
    select 
        name,
        (select sum(size) from fs where type = 0 and fs.database_id = db.database_id) DataFileSizeMB,
        (select sum(size) from fs where type = 1 and fs.database_id = db.database_id) LogFileSizeMB,
        (select sum(size) from fs where fs.database_id = db.database_id) TotalFileSizeMB
    from sys.databases db
    --order by database_id
    order by TotalFileSizeMB desc

```