C# – Change DataFile MaxSize using SMO

c++smo

I am trying to modify the Maxsize of an sql 2008 Datafile, but the change does not happend.

I`m using this code:

FileGroupCollection fcoll = database.FileGroups;
foreach (FileGroup grp in fcoll)
{
    foreach (DataFile fil in grp.Files)
    {
        fil.MaxSize = 1000;
    }
}

I get no error message, but the max size of the DataFile does not change.

Any suggestions to what I`m doing wrong?
Thanx.

Best Solution

You need to call the Alter() method.

FileGroupCollection fcoll = database.FileGroups;
foreach (FileGroup grp in fcoll)
{
    foreach (DataFile fil in grp.Files)
    {
        fil.MaxSize = 1000;
        fil.Alter(); //<---- add this!
    }
}