static void Main(string[] args) { var connStrBldr = new SqlConnectionStringBuilder { UserID = _userName, Password = _pasword, IntegratedSecurity = false, ApplicationName = _applicationName }; //Get an instance of our ShardMapManager (contained in ShardingClient wrapper) Console.WriteLine("Checking for existing shard map and creating new shard map if necessary."); var sharding = new ShardingClient(_shardServer, _shardMapManagerDb, connStrBldr.ConnectionString); Console.WriteLine("Executing Multishard Query"); var results = ExecuteMultiShardQuery(ref sharding, connStrBldr.ConnectionString); Console.WriteLine("Multishard Query Results *******************************"); if (results.Count > 0) { foreach (var item in results) { Console.WriteLine($"BlogId:{item.BlogId}\tBlogName:{item.Name}"); } } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
private static List <dynamic> ExecuteMultiShardQuery(ref ShardingClient sharding, string connectionString) { dynamic result = new List <dynamic>(); var multiShardConnection = new MultiShardConnection(sharding.ShardMap.GetShards(), connectionString); using (var cmd = multiShardConnection.CreateCommand()) { cmd.CommandText = @"SELECT * FROM dbo.Blogs"; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandTimeoutPerShard = 60; using (var reader = cmd.ExecuteReader()) { if (reader.HasRows) { result = reader.ToExpandoList(); } } } return(result); }