Reputation: 683
I would like to move the DB's of AG to new location(on a new drive ). There is a nice article present on msdn which uses SQLCmd utility to do the same, but I would like to do it from C# code.
please help me what are all the steps do we need to follow to move.
Regards Ashish
Upvotes: 0
Views: 1699
Reputation: 683
It differs whether are we moving DB on primary replica or Secondary. Below mention are the steps for both the replicas...
1.) Primary Replica:- Detach DB from all the secondary replicas AG Detach DB from the primary replica AG Issue ALter DB T-SQL command for the DB which needs to be moved. Copy the db files to the new destination. Attach the DB back on primary replica AG Attach the DB back on all Secondary replicas AG
2.) Secondary replica:- Take a full backup of DB. Take a t log backup of DB detach the DB from the AG restore DB using backup created earlier and restore to destination location. Attach the DB back to AG
Upvotes: 0
Reputation: 206
Here is a resource for SMO programming, perhaps you will find what you need in the guide.
I must admit though, administering SQL Server from managed code is not something I would recommend unless your product is aimed at administering SQL Server. Alternatively look at doing this from Powershell and then controlling your scripts/cmdlets from your managed application.
Here is another resource with a list of cmdlets for managing SQL Server Availability Groups.
Finally Get Help SQL Server Powershell
Upvotes: 2