/// <summary> /// Gets the properties of the database. /// These properties include database status, owner, create date, file properties, and more. /// </summary> /// <returns> /// The properties of the database. /// </returns> public SqlDatabaseProperties GetDatabaseProperties() { string databaseStatus; switch (dmoDatabase.GetStatus()) { case NativeMethods.SQLDMO_DBSTATUS_TYPE.SQLDMODBStat_EmergencyMode: databaseStatus = SR.GetString("SqlDatabase_Status_EmergencyMode"); break; case NativeMethods.SQLDMO_DBSTATUS_TYPE.SQLDMODBStat_Inaccessible: databaseStatus = SR.GetString("SqlDatabase_Status_Inaccessible"); break; case NativeMethods.SQLDMO_DBSTATUS_TYPE.SQLDMODBStat_Loading: databaseStatus = SR.GetString("SqlDatabase_Status_Loading"); break; case NativeMethods.SQLDMO_DBSTATUS_TYPE.SQLDMODBStat_Normal: databaseStatus = SR.GetString("SqlDatabase_Status_Normal"); break; case NativeMethods.SQLDMO_DBSTATUS_TYPE.SQLDMODBStat_Offline: databaseStatus = SR.GetString("SqlDatabase_Status_Offline"); break; case NativeMethods.SQLDMO_DBSTATUS_TYPE.SQLDMODBStat_Recovering: databaseStatus = SR.GetString("SqlDatabase_Status_Recovering"); break; case NativeMethods.SQLDMO_DBSTATUS_TYPE.SQLDMODBStat_Standby: databaseStatus = SR.GetString("SqlDatabase_Status_Standby"); break; case NativeMethods.SQLDMO_DBSTATUS_TYPE.SQLDMODBStat_Suspect: databaseStatus = SR.GetString("SqlDatabase_Status_Suspect"); break; default: databaseStatus = SR.GetString("SqlDatabase_Status_Unknown"); break; } NativeMethods.IDBFile dataFile = dmoDatabase.GetFileGroups().Item(1).GetDBFiles().Item(1); NativeMethods.ILogFile logFile = dmoDatabase.GetTransactionLog().GetLogFiles().Item(1); SqlFileProperties dataFileProps = new SqlFileProperties((dataFile.GetFileGrowthType() == NativeMethods.SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB) ? SqlFileGrowthType.MB : SqlFileGrowthType.Percent, dataFile.GetFileGrowth(), dataFile.GetMaximumSize()); SqlFileProperties logFileProps = new SqlFileProperties((logFile.GetFileGrowthType() == NativeMethods.SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB) ? SqlFileGrowthType.MB : SqlFileGrowthType.Percent, logFile.GetFileGrowth(), logFile.GetMaximumSize()); SqlDatabaseProperties props = new SqlDatabaseProperties(dmoDatabase.GetName(), databaseStatus, dmoDatabase.GetOwner(), DateTime.Parse(dmoDatabase.GetCreateDate()), dmoDatabase.GetSize(), dmoDatabase.GetSpaceAvailable() / 1024F, dmoDatabase.GetUsers().GetCount(), dataFileProps, logFileProps); return(props); }
/// <summary> /// Sets data file and transaction log file properties for this database. /// </summary> /// <param name="props"> /// A list of properties to set. /// </param> /// <remarks> /// Only the data file and transaction log file properties are used. /// You cannot set the owner, create date, etc. properties of the database. /// </remarks> public void SetDatabaseProperties(SqlDatabaseProperties props) { NativeMethods.IDBFile dataFile = dmoDatabase.GetFileGroups().Item(1).GetDBFiles().Item(1); NativeMethods.ILogFile logFile = dmoDatabase.GetTransactionLog().GetLogFiles().Item(1); dataFile.SetFileGrowthType((props.DataFile.FileGrowthType == SqlFileGrowthType.MB) ? NativeMethods.SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB : NativeMethods.SQLDMO_GROWTH_TYPE.SQLDMOGrowth_Percent); dataFile.SetFileGrowth(props.DataFile.FileGrowth); dataFile.SetMaximumSize(props.DataFile.MaximumSize); logFile.SetFileGrowthType((props.LogFile.FileGrowthType == SqlFileGrowthType.MB) ? NativeMethods.SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB : NativeMethods.SQLDMO_GROWTH_TYPE.SQLDMOGrowth_Percent); logFile.SetFileGrowth(props.LogFile.FileGrowth); logFile.SetMaximumSize(props.LogFile.MaximumSize); }