tag:help.appveyor.com,2012-11-13:/discussions/questions/394-installing-a-database-from-mdfAppVeyor: Discussion 2018-10-19T08:16:38Ztag:help.appveyor.com,2012-11-13:Comment/336984522014-07-08T15:40:35Z2014-07-08T15:40:35ZInstalling a database from mdf. <div><p>It is admin. "appveyor" user account is a member of
"Administrators" group. This because by default
<code>C:\Windows\System32\WindowsPowerShell\v1.0</code> has "Read"
only permissions for both SYSTEM and Administrators. Presumably,
you should first change ACLs on that folder/file (say, using
<code>cacls</code> utility) and then modify the file.</p>
<p>Alternatively, I'd use <code>sqlcmd</code> and <a href=
"http://msdn.microsoft.com/en-us/library/ms179877.aspx"><code>sp_attach_db</code>
command</a> instead of PS.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/336984522014-07-09T15:16:50Z2014-07-09T15:16:50ZInstalling a database from mdf. <div><p>OK got that working with sqlcmd. Thanks for the suggestion a lot
easier than trying to wrestle with SQLPS !</p></div>scascarinitag:help.appveyor.com,2012-11-13:Comment/336984522015-02-12T14:53:35Z2015-02-12T14:53:35ZInstalling a database from mdf. <div><p>@scascarini what was the script you used for
<code>sqlcmd</code>? I'm having trouble using
<code>sp_attach_db</code> via <code>sqlcmd</code>.</p>
<p>The error is</p>
<pre>
<code>Msg 3415, Level 16, State 2, Server APPVYR-WIN20122\SQL2014, Line 1
Database 'ControllerTests.Web' cannot be upgraded because it is read-only, has read-only files or the user does not have permissions to modify some of the files. Make the database or files writeable, and rerun recovery.</code>
</pre></div>cottsaktag:help.appveyor.com,2012-11-13:Comment/336984522015-02-12T15:31:22Z2015-02-12T15:31:22ZInstalling a database from mdf. <div><p>This works for me</p>
<pre>
<code>sqlcmd -S (local)\SQL2012SP1 -Q "Use [master]; CREATE DATABASE [AdventureWorks] ON (FILENAME = 'C:\projects\<proj>\AdventureWorks_Data.mdf'),(FILENAME = 'C:\projects\<proj>\AdventureWorks_Log.ldf') for ATTACH"</code>
</pre></div>scascarinitag:help.appveyor.com,2012-11-13:Comment/336984522015-02-13T00:07:47Z2015-02-13T00:07:47ZInstalling a database from mdf. <div><p>Awesome! Did you have to do anything to the permissions on those
<code>mdf</code> and <code>ldf</code> files to make them accessible
to your script?</p></div>cottsaktag:help.appveyor.com,2012-11-13:Comment/336984522015-02-13T01:11:04Z2015-02-13T01:11:04ZInstalling a database from mdf. <div><p>@scascarini I got my stuff working thanks to your help.
Cheers</p>
<p><a href=
"http://help.appveyor.com/discussions/questions/943-my-localdb-connection-string-isnt-letting-me-access-my-mdf-file">
http://help.appveyor.com/discussions/questions/943-my-localdb-conne...</a></p></div>cottsak