views:

178

answers:

1

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.

+2  A: 

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