Back to list
Views:   2.4K
Replies:  0
Archived

Get Connection String in Regedit

In my project use Pattern In Action Framework 4.0

We need change connection string any time from database

Now, in pattern in action framework connection string is a static variable, it can't re initialize  when connection string was changed by database

you could you help me to reslove this problem

Our solution, but sometime connection.Open annouce error connection state



using (var connection = Factory.CreateConnection())
            {
                Debug.Assert(connection != null, "connection != null");

                var _connectionString = string.Format("Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3}",
                                                                  GetValueByRegistryKey("InstanceName"),
                                                                  GetValueByRegistryKey("DatabaseName"),
                                                                  GetValueByRegistryKey("UserName"),
                                                                  GetValueByRegistryKey("Password"));
                connection.ConnectionString = _connectionString;

                using (var command = Factory.CreateCommand())
                {
                    Debug.Assert(command != null, "command != null");
                    command.Connection = connection;
                    command.CommandType = isProcedure ? CommandType.StoredProcedure : CommandType.Text;
                    command.CommandText = sql;
                    command.SetParameters(parms);  // Extension method

                    connection.Open();

                    T t = default(T);
                    var reader = command.ExecuteReader();
                    if (reader.Read())

                        t = make(reader);

                    return t;
                }
            }

 
Frederick Nguyen, Aug 25, 2017


Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas.      Vsn 1.3.0