Set Recovery Mode on a target database

Automated deployment for web applications and databases

Moderators: Mike Upton, justin.caldicott, Sean.newham, csmith, chirayu, DavidSimner, david.conlin

Set Recovery Mode on a target database

Postby swinghouse » Thu Apr 03, 2014 11:12 am

Is it possible to set Recovery Mode on a database being deployed by Deployment Manager? Perhaps with a PowerShell script?

I would like to be able to automatically set our test databases in Simple Recovery Mode.
swinghouse
 
Posts: 99
Joined: Mon Sep 12, 2011 10:51 am

Postby Chris.Allen » Mon Apr 07, 2014 2:52 pm

Yes, this is possible. Powershell + SQLCMD is fully supported.

I'll take a very quick look at the powershell forum to see if there's anything already there.
Chris.Allen
 
Posts: 594
Joined: Thu Mar 12, 2009 4:17 pm

Postby Chris.Allen » Mon Apr 07, 2014 3:00 pm

Couldn't find it on the forums but here's a simple example that should help:

https://community.rackspace.com/products/f/18/t/1630
Chris.Allen
 
Posts: 594
Joined: Thu Mar 12, 2009 4:17 pm

Postby swinghouse » Sun Apr 20, 2014 9:20 pm

Thank you Chris,

Got a modified version of that sample from https://community.rackspace.com/products/f/18/t/1630 working in the PostDeploy.ps1 script of a Deployment Manager project.

I didn't get the script to work with string representations of the RecoveryModel options, but had to use the enum representation like so:

Code: Select all
[Microsoft.SqlServer.Management.Smo.RecoveryModel]::Simple


And to apply SQL Server Authentication I had to add:

Code: Select all
#This sets the connection to mixed-mode authentication
$smo.ConnectionContext.LoginSecure=$false;

#This sets the login name
$smo.ConnectionContext.set_Login("$databaseUserName");

#This sets the password
$smo.ConnectionContext.set_Password("$databasePassword")


after instantiating the $smo object.

Thanks for the help!
swinghouse
 
Posts: 99
Joined: Mon Sep 12, 2011 10:51 am


Return to Deployment Manager

Who is online

Users browsing this forum: No registered users and 0 guests