Exemple #1
0
        /// <summary>
        /// Get connection user and password.
        /// </summary>
        /// <param name="connectionName">Connection name</param>
        /// <returns></returns>
        public static string[] GetUserPassword(string connectionName)
        {
            string[] result = new string[] { "", "" };

            string cs = LibraryHelper.ConnectionStrings(connectionName);

            string[] tokens = cs.Split(';');

            for (var i = 0; i < tokens.Length; i++)
            {
                var token = tokens[i];
                if (token.StartsWith("User ID"))
                {
                    result[0] = token.Substring(token.IndexOf("=") + 1);
                }

                if (token.StartsWith("Password"))
                {
                    result[1] = token.Substring(token.IndexOf("=") + 1);
                }
            }

            // using System.Linq;
            //string connectionString = LibraryHelper.ConnectionStrings(connectionName);
            //var tokens = connectionString.Split(';').Select(x => x.Split('='));
            //string userId = tokens.First(n => n[0].Equals("User ID").Select(x => x[1]);
            //string password = tokens.First(n => n[0].Equals("Password")).Select(x => x[1]);

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Get connection string by connection name.
        /// </summary>
        /// <param name="connectionName">Connection name</param>
        /// <returns></returns>
        public static string GetConnectionString(string connectionName)
        {
            string connectionString = LibraryHelper.ConnectionStrings(connectionName);

            return(connectionString);
        }