Created
February 14, 2015 01:37
-
-
Save FeodorFitsner/6a734f5ee48de949df02 to your computer and use it in GitHub Desktop.
Attaching MDF file with existing SQL Server database on AppVeyor and updating configuration connection string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$startPath = "$($env:appveyor_build_folder)\path-to-your-bin" | |
$sqlInstance = "(local)\SQL2012SP1" | |
$dbName = "MyDatabase" | |
# replace the db connection with the local instance | |
$config = join-path $startPath "MyTests.dll.config" | |
$doc = (gc $config) -as [xml] | |
$doc.SelectSingleNode('//connectionStrings/add[@name="store"]').connectionString = "Server=$sqlInstance; Database=$dbName; Trusted_connection=true" | |
$doc.Save($config) | |
# attach mdf to local instance | |
$mdfFile = join-path $startPath "store.mdf" | |
$ldfFile = join-path $startPath "store_log.ldf" | |
sqlcmd -S "$sqlInstance" -Q "Use [master]; CREATE DATABASE [$dbName] ON (FILENAME = '$mdfFile'),(FILENAME = '$ldfFile') for ATTACH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment