title: Sql SMO: How to get path of database physical file name?
body: <p>I am trying to return the physical file path of a database's mdf/ldf files.</p>
  
  <p>I have tried using the following code:</p>
  
  <pre><code>Server srv = new Server(connection);
  Database database = new Database(srv, dbName);
  
  string filePath = database.PrimaryFilePath;
  </code></pre>
  
  <p>However this throws an exception "'database.PrimaryFilePath' threw an exception of type 'Microsoft.SqlServer.Management.Smo.PropertyNotSetException' - even though the database I'm running this against exists, and its mdf file is located in c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL</p>
  
  <p>What am I doing wrong?</p>