title: Permissions on new mdf file
body: <p>I'm trying to write a program to allow a non-privileged technically naive user to create a new SQL Server database and receive it in the form of a <code>.mdf</code> file. I understand that <code>.mdf</code> files are not really supposed to be treated like database backups, but I need to do it this way to maintain compatibility with existing commercial software that works like this.</p>
  
  <p>I'm using Visual Studio 2013 and SQL Server 2014, though I would like the program to be able to work with versions of SQL Server going back at least to 2008.</p>
  
  <p>What I find is that I can't copy the <code>.mdf</code> file created by </p>
  
  <pre><code>CREATE DATABASE XXXXX on 
  (NAME=&lt;name&gt;,FILENAME=&lt;filename&gt;')
  </code></pre>
  
  <p>because it ends up belonging (I think) to <code>MSSQL$SQLEXPRESS</code>. The reason I say 'I think' is that when I go to the file properties and accept Administrator privileges to view the owner, it tells me 'Unable to display current owner.' I can transfer ownership of the file, but only using Administrator privileges.</p>
  
  <p>So it seems that I cannot copy the <code>.MDF</code> file without Administrator privileges, which seems fairly ridiculous given that I was able to create the file without those privileges. I've tried creating the file in a folder located under my user's <code>App_Data</code> folder and with full access for everyone to subfolders and files, but that didn't help. </p>
  
  <p>Can anyone suggest me what I can do (programatically) to make this file available to a non-privileged user?</p>
  
  <p>Many thanks for your help.</p>