0

I am afraid that i am unable to locate the absolute path of the SQL SERVER data files.

I have tried to so do by doing the following.

    foreach( Database db in srv.Databases)
     string filepath=db.PrimaryFilepath;
     string name=db.Name;
     abspth=filepath+"//"+name+".mdf";

Like this i have workaround.But is there is any alternative to get the absolute path.

But in case of logfiles it gives absolute path.......

Help me in this regard...

Thanks in Advance.

John Sansom
  • 41,005
  • 9
  • 72
  • 84
Cute
  • 13,643
  • 36
  • 96
  • 112

1 Answers1

2

The Database in SMO should contain a Filegroups collection which in turn contains a Files collection - you should find your file path's in there.

        foreach(FileGroup fg in db.FileGroups)
        {
            foreach(DataFile df in fg.Files)
            {
                Console.WriteLine("File path: {0}", df.FileName);
            }
        }

Marc

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459