﻿using System.Linq;
using System.Xml.Linq;

namespace Tests.Daterpillar.Helpers
{
    public static class ConnectionString
    {
        private static readonly string _configFile = "database.config.xml";

        public static string GetMySQLServerConnectionString()
        {
            return GetConnectionString("mysql");
        }

        public static string GetSQLServerConnectionString()
        {
            return GetConnectionString("mssql");
        }

        internal static string GetConnectionString(string name)
        {
            var doc = XDocument.Load(_configFile);
            var connectionStrings = doc.Element("connectionStrings");

            var record = (from element in connectionStrings.Descendants("add")
                          where element.Attribute("name").Value == name
                          select element)
                          .First();

            var connStr = new System.Data.Common.DbConnectionStringBuilder();
            connStr.Add("server", record.Attribute("server").Value);
            connStr.Add("user", record.Attribute("user").Value);
            connStr.Add("password", record.Attribute("password").Value);

            return connStr.ConnectionString;
        }
    }
}
﻿using System.Configuration;

namespace Tests.Daterpillar.Helpers
{
    public static class ConnectionString
    {
        public static string GetMySQLServerConnectionString()
        {
            return GetConnectionString("mysql");
        }

        public static string GetSQLServerConnectionString()
        {
            return GetConnectionString("mssql");
        }

        internal static string GetConnectionString(string name)
        {
            var fileMap = new ExeConfigurationFileMap() { ExeConfigFilename = "user.config" };
            var config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

            return config.ConnectionStrings.ConnectionStrings[name].ConnectionString;
        }
    }
}
Change user.config format to app.confg schema
Change user.config format to app.confg schema
