Example #1
0
        static DbConfig()
        {
            try
            {
                String server = String.Empty;
                String database = String.Empty;
                String userId = String.Empty;
                String password = String.Empty;
                ConnectionList = new List<Connection>();
                foreach (ConnectionStringSettings conString in WebConfigurationManager.ConnectionStrings)
                {
                    if (conString.Name.Equals("LocalSqlServer")) continue;
                    if (conString.Name.Equals("OraAspNetConString")) continue;
                    String[] serverInfo = conString.ConnectionString.Split(";".ToCharArray(),StringSplitOptions.RemoveEmptyEntries);

                    foreach(String info in serverInfo)
                    {
                        if (info.Trim().ToLower().StartsWith("data source") || info.Trim().ToLower().StartsWith("server"))
                        {
                            server = info.Split('=')[1].Trim();
                        }
                        else if (info.Trim().ToLower().StartsWith("user id") || info.Trim().ToLower().StartsWith("user") || info.Trim().ToLower().StartsWith("uid"))
                        {
                            userId = info.Split('=')[1].Trim();
                        }
                        else if (info.Trim().ToLower().StartsWith("pwd") || info.Trim().ToLower().StartsWith("password"))
                        {
                            password = info.Split('=')[1].Trim();
                        }
                        else if (info.Trim().ToLower().StartsWith("initial catalog") || info.Trim().ToLower().StartsWith("database"))
                        {
                            database = info.Split('=')[1].Trim();
                        }

                    }
                    var connection = new Connection
                                         {
                                             Name = conString.Name,
                                             Provider = (Util.ConnectionLibrary)Enum.Parse(typeof(Util.ConnectionLibrary), conString.ProviderName),
                                             ConnectionString = conString.ConnectionString,
                                             Default = conString.LockItem,
                                             Server = server,
                                             Database = database,
                                             UserId = userId,
                                             Password = password
                                         };
                    ConnectionList.Add(connection);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Example #2
0
        private Boolean MakeConnectionString(Connection connection)
        {
            try
            {
                String connectionString = connection.ConnectionString;
                connectionString += String.Format("; {0}", ConnectionTimeOut);
                // Provider
                var provider = connection.Provider;
                Initailize(connectionString, provider);

                return true;

            }
            catch
            {
                return false;
            }
        }
Example #3
0
 private static Boolean MakeConnectionInfo(Connection connection, ref String conString, ref Util.ConnectionLibrary provider)
 {
     try
     {
         conString = connection.ConnectionString;
         conString += String.Format("; {0}", ConnectionTimeOut);
         // provider
         provider = connection.Provider;
         return true;
     }
     catch
     {
         return false;
     }
 }