/// <summary> /// Creates availability group using Smo /// </summary> /// <param name="agName">Availability group name.</param> /// <param name="dbNames">Datbases to be part of the AG.</param> /// <param name="replicas">replicas to be part of the AG.</param> /// <param name="server">smo server.</param> public static AvailabilityGroup CreateAG(string agName, IEnumerable <string> dbNames, IEnumerable <Smo.Server> replicas, Smo.Server server) { if (!AGHelper.IsAGExist(agName, server)) { AvailabilityGroup ag = new AvailabilityGroup(server, agName); foreach (string dbName in dbNames) { ag.AvailabilityDatabases.Add(new AvailabilityDatabase(ag, dbName)); } foreach (Smo.Server replica in replicas) { AvailabilityReplica ar = new AvailabilityReplica(ag, replica.Name); ar.EndpointUrl = ARHelper.GetHadrEndpointUrl(replica); ar.AvailabilityMode = AvailabilityReplicaAvailabilityMode.AsynchronousCommit; ar.FailoverMode = AvailabilityReplicaFailoverMode.Manual; ag.AvailabilityReplicas.Add(ar); } ag.Create(); return(ag); } else { throw new Exception(string.Format("The requested availability Group {0} already exist in the given server {1}", agName, server.Name)); } }
public void Setup() { agName = "HadrBenchTest"; baseDBpath = @"\\zechen-d1\dbshare\"; dbshare = @"\\zechen-d1\dbshare\bench\"; //primaryServerName = @"ze-2016-v1\sql16rtm01"; //secondaryServerName = @"ze-2016-v2\sql16rtm01"; // start point of dbCount, lets say 500 primaryDbsNames = new List <string>(); primaryDbs = new List <Database>(); dbCacheLock = new ReaderWriterLockSlim(); dbCount = 0; // create three replicas replicas = new List <Server>(); secondaries = new List <Server>(); replicaEndpointUrls = new List <string>(); primaryServerName = string.Empty; Smo.Server srv; srv = new Smo.Server(@"ze-bench-01\hadrBenchMark01"); replicas.Add(srv); // primary is important primaryServerName = @"ze-bench-01\hadrBenchMark01"; primary = srv; //report server always point to 01 reportSrv = srv; reportServerName = primaryServerName; reportDBName = @"FailoverResult"; string username = "******"; string password = "******"; reportConnecionString = string.Format("server={0}; Initial Catalog={1};uid={2}; pwd={3} ", primaryServerName, reportDBName, username, password); srv = new Smo.Server(@"ze-bench-02\hadrBenchMark01"); replicas.Add(srv); secondaries.Add(srv); srv = new Smo.Server(@"ze-bench-03\hadrBenchMark01"); replicas.Add(srv); secondaries.Add(srv); string replicaEndpointUrl = string.Empty; foreach (Smo.Server server in replicas) { replicaEndpointUrl = ARHelper.GetHadrEndpointUrl(server); replicaEndpointUrls.Add(replicaEndpointUrl); } if (!AGHelper.IsAGExist(agName, primary)) { TestCreateAGWithTwoReplicasWithoutDatabase(); } this.notConnectedDBs = new List <string>(); stopBackup = false; }