Cute
Cute

Reputation: 14011

How to display ndf files using SMO?

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 ;           

                 }
           }

Upvotes: 0

Views: 589

Answers (1)

Andrew
Andrew

Reputation: 27294

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
            }
    }
}

Upvotes: 2

Related Questions