/// <summary>
        /// Retrieves a list of connection properties from the layers of a <see cref="IMapServer"/>.
        /// </summary>
        /// <param name="mapServer">A map server.</param>
        /// <param name="propertyNames">The names of the keys in each dictionary of the output object.</param>
        /// <returns>
        /// A list of <see cref="KeyValuePair&lt;TKey,KValue&gt;"/> objects.  
        /// Each <see cref="KeyValuePair&lt;TKey,KValue&gt;.Key"/> corresponds to a data source name.
        /// Each value is a <see cref="Dictionary&lt;TKey,TValue&gt;"/> of connection properties.
        /// </returns>
        public static List<ConnectionProperties> GetConnectionProperties(this IMapServer mapServer /*, out List<string> propertyNames*/ )
        {
            IMapLayerInfos mapLayerInfos = null;
            IMapLayerInfo mapLayerInfo = null;
            IMapServerDataAccess mapServerDA = null;
            IMapServerInfo mapServerInfo = null; ;
            ////propertyNames = new List<string>();
            IDataset dataset = null;
            IPropertySet connectionPropertySet = null;
            object namesObj, valuesObj;
            string[] names;
            object[] values;

            var output = new List<ConnectionProperties>();

            try
            {
                mapServerDA = (IMapServerDataAccess)mapServer;
                // Get the server info for the default map. (This application will assume that there is only a single map: the default.)
                string mapName = mapServer.DefaultMapName;
                mapServerInfo = mapServer.GetServerInfo(mapName);
                // Loop through all of the layers in the map service...
                mapLayerInfos = mapServerInfo.MapLayerInfos;

                ConnectionProperties connectionProperties;

                for (int i = 0, l = mapLayerInfos.Count; i < l; i++)
                {
                    mapLayerInfo = mapLayerInfos.get_Element(i);
                    if (mapLayerInfo.IsComposite)
                    {
                        continue;
                    }

                    connectionProperties = new ConnectionProperties(mapLayerInfo.Name);
                    try
                    {
                        dataset = mapServerDA.GetDataSource(mapName, i) as IDataset;
                    }
                    catch (NotImplementedException ex)
                    {
                        connectionProperties["error"] = ex.Message;
                        output.Add(connectionProperties);
                        continue;
                    }

                    if (dataset != null)
                    {
                        connectionPropertySet = dataset.Workspace.ConnectionProperties;
                        connectionPropertySet.GetAllProperties(out namesObj, out valuesObj);
                        names = namesObj as string[];
                        values = valuesObj as object[];

                        string name;
                        for (int j = 0; j < names.Length; j++)
                        {
                            name = names[j];
                            connectionProperties[name] = values[j];
                        }
                        output.Add(connectionProperties);
                    }
                }
            }
            finally
            {
                foreach (var item in new object[] {mapLayerInfos, mapLayerInfo, mapServerDA, mapServerInfo, dataset, connectionPropertySet})
                {
                    if (item != null)
                    {
                        Marshal.ReleaseComObject(item);
                    }
                }
            }

            return output;
        }