views:

112

answers:

1

Hi

I am using SMO to populate the list of database files log files. i am using filegroups but it displays only mdf and ldf files. I have ndf files also it is not dispalying ndf files?? what i have to do any suggestions plz???

           string dbname = string.Empty, DatabaseInfo = string.Empty;
           Server srv = new Server(instanceName);
           foreach (Database db in srv.Databases)
           {
                 if (DB.Equals(db.Name))
                 {
                   DatabaseInfo += db.FileGroups[0].Files[0].FileName;
                  string logfile=db.LogFiles[0].FileName ;           

                 }
           }
+2  A: 

Sorry if this is stating something a bit obvious, but you are specifically accessing the first filegroup and first file of that group. If you do not enumerate the filegroups and files collection, why would you expect to see the secondary files?

Edit : Added a code extract.

foreach (Database db in srv.Databases)  
{
    if (DB.Equals(db.Name))                 
    { 
            foreach (FileGroup fg in db.FileGroups)
            {
                foreach(DataFile df in fg.Files)
                {
                    // do whatever you planned to do with df.FileName.
                }
            }
            foreach (LogFile log in db.LogFiles)
            {
                // do whatever you planned to do with the log.FileName
            }
    }
}
Andrew
Filegroups, Files and LogFiles are all collections, enumerate on those instead of taking the first item [0]
Andrew