Пример #1
0
 private void RunScripts(InstallerConfig config)
 {
     string[] files = Directory.GetFiles(config.Path.AppPath + config.Path.RelativeSqlPath);
     foreach (string file in files)
     {
         string[] statements = GetScriptStatements(File.ReadAllText(file, new System.Text.UTF8Encoding()));
         ExecuteStatements(statements, config);
     }
 }
Пример #2
0
        public FactoryTests()
        {
            // You need to remember to remove the ".config" in the filename for it to work correctly.
            // The ConfigurationManager tacks on a trailing ".config" to the filename.
            // C:\VSProjects\MvcInstaller\RuleValidationFactory.Tests\bin\Debug\RuleValidationFactory.Tests.dll.config.config
            // So if the actual filename is "RuleValidationFactory.Tests.dll.config",
            // then you have to enter, RuleValidationFactory.Tests.dll for it to work.
            _configSection = ConfigurationManager.OpenExeConfiguration(AppDomain.CurrentDomain.BaseDirectory + @"\RuleValidationFactory.Tests.dll");

            _config = Serializer<InstallerConfig>.Deserialize(AppDomain.CurrentDomain.BaseDirectory + @"\installer.config");

            _factory = new RulesValidationFactory(_config, _configSection);
        }
        public void return_standard_connection_string_using_trustedconnection()
        {
            // Arrange
            InstallerConfig config = new InstallerConfig();
            config.Database.DataSource = @"kingwilder-pc\sqlserver";
            config.Database.InitialCatalog = "BloggerApp";
            config.Database.UseTrustedConnection = true;

            ConnectionFactory factory = new ConnectionFactory(config);

            // Act
            var actual = factory.ConnectionString();
            var expected = string.Format("Data Source={0};Initial Catalog={1};Integrated Security=True", config.Database.DataSource, config.Database.InitialCatalog);

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void return_entityframework_connection_using_trustedconnection()
        {
            // Arrange
            InstallerConfig config = new InstallerConfig();
            config.Database.DataSource = @"kingwilder-pc\sqlserver";
            config.Database.InitialCatalog = "BloggerApp";
            config.Database.UseTrustedConnection = true;
            config.Database.EntityFrameworkEntitiesName = "BloggerEntities";

            ConnectionFactory factory = new ConnectionFactory(config);

            // Act
            var actual = factory.ConnectionString();
            var expected = @"metadata=res://*/Models.BloggerEntities.csdl|res://*/Models.BloggerEntities.ssdl|res://*/Models.BloggerEntities.msl;provider=System.Data.SqlClient;provider connection string=""Data Source=kingwilder-pc\sqlserver;Initial Catalog=BloggerApp;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework""";

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void return_standard_connection_string_with_credentials()
        {
            // Arrange
            InstallerConfig config = new InstallerConfig();
            config.Database.DataSource = @"kingwilder-pc\sqlserver";
            config.Database.InitialCatalog = "BloggerApp";
            config.Database.UseTrustedConnection = false;
            config.Database.UserName = "******";
            config.Database.Password = "******";

            ConnectionFactory factory = new ConnectionFactory(config);

            // Act
            var actual = factory.ConnectionString();
            var expected = string.Format("Data Source={0};Initial Catalog={1};User ID={2};Password={3}", config.Database.DataSource, config.Database.InitialCatalog, config.Database.UserName, config.Database.Password);

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #6
0
 /// <summary>
 /// This will execute the sql statements.
 /// </summary>
 /// <param name="tableStatements"></param>
 /// <param name="dbName"></param>
 private void ExecuteStatements(string[] tableStatements, InstallerConfig config)
 {
     if (tableStatements.Length > 0)
     {
         using (SqlConnection conn = new SqlConnection())
         {
             IConnectionStringComponent component = new ConnectionStringComponent(config);
             conn.ConnectionString = component.GetConnString();
             conn.Open();
             using (SqlCommand command = new SqlCommand(string.Empty, conn))
             {
                 foreach (string statement in tableStatements)
                 {
                     command.CommandText = statement;
                     command.ExecuteNonQuery();
                 }
             }
         }
     }
 }
Пример #7
0
        /// <summary>
        /// Update the web.config connection strings. If the EntityFramework is being used, two connection strings
        /// will be created. One for the EntityFramework, and another for the Membership system.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="configSection"></param>
        private void UpdateConnectionString(InstallerConfig config, Configuration configSection)
        {
            string connString = component.GetConnString();
            string providerName = "System.Data.SqlClient";
            if (!string.IsNullOrEmpty(config.Database.EntityFrameworkEntitiesName))
            {
                providerName = "System.Data.EntityClient";
                connString = component.BuildEntityFrameworkConnectionString();
            }

            ConnectionStringsSection connectionStringsSection = configSection.ConnectionStrings;
            ConnectionStringSettings appTemplate = new ConnectionStringSettings(config.Database.ConnectionStringName, connString, providerName);
            connectionStringsSection.ConnectionStrings.Clear();
            connectionStringsSection.ConnectionStrings.Add(appTemplate);

            if (!string.IsNullOrEmpty(config.Database.EntityFrameworkEntitiesName) && config.Membership.Create)
            {
                ConnectionStringSettings connTemplate = new ConnectionStringSettings("MembershipConnection", component.GetConnString(), "System.Data.SqlClient");
                connectionStringsSection.ConnectionStrings.Add(connTemplate);
            }
        }
        public void Serialize_xml_config_settings_from_class()
        {
            InstallerConfig config = new InstallerConfig();

            //User user = new User();
            //user.UserName = "******";
            //user.Password = "******";

            //Role role = new Role();
            //role.Name = "SuperAdministrator";
            //role.AddUser(user);
            //config.AddRole(role);

            //role = new Role();
            //role.Name = "Administrator";

            //user = new User();
            //user.UserName = "******";
            //user.Password = "******";

            //role.AddUser(user);

            //user = new User();
            //user.UserName = "******";
            //user.Password = "******";

            //role.AddUser(user);
            //config.AddRole(role);

            Database db = new Database();
            db.ConnectionStringName = "MyCoolConnection";
            db.DataSource = "localhost";
            db.InitialCatalog = "MyCoolDb";
            db.UserName = "******";
            db.Password = "******";
            config.Database = db;

            Serializer<InstallerConfig>.Serialize(config, "installer.config");
        }
        public string GetConnString(InstallerConfig config, string dbName)
        {
            string connString = "Data Source=" + config.Database.DataSource.Trim() + ";";
            if (!string.IsNullOrEmpty(dbName))
            {
                connString += "Initial Catalog=" + dbName + ";";
            }
            else
            {
                connString += "Initial Catalog=" + config.Database.InitialCatalog + ";";
            }

            if (config.Database.UseTrustedConnection)
            {
                connString += "Integrated Security=true;";
            }
            else
            {
                connString += "User ID=" + config.Database.UserName.Trim() + ";Password="******";";
            }
            return connString;
        }
Пример #10
0
        /// <summary>
        /// Update the web.config connection strings. If the EntityFramework is being used, two connection strings
        /// will be created. One for the EntityFramework, and another for the Membership system.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="configSection"></param>
        private void UpdateConnectionString(InstallerConfig config, Configuration configSection)
        {
            ConnectionStringsSection connectionStringsSection = configSection.ConnectionStrings;

            string connString = string.Empty;
            string providerName = string.Empty;

            if (!string.IsNullOrEmpty(config.Database.EntityFrameworkEntitiesName))
            {
                // EntityFramework connection string
                providerName = component.GetProviderName;
                connString = component.GetConnString();

                string efname = config.Database.EntityFrameworkEntitiesName;

                ConnectionStringSettings appTemplate = new ConnectionStringSettings(config.Database.EntityFrameworkEntitiesName, connString, providerName);
                connectionStringsSection.ConnectionStrings.Clear();
                connectionStringsSection.ConnectionStrings.Add(appTemplate);

                if (!string.IsNullOrEmpty(config.Database.EntityFrameworkEntitiesName) && config.Membership.Create)
                {
                    config.Database.EntityFrameworkEntitiesName = "";
                    ConnectionStringSettings connTemplate = new ConnectionStringSettings("MembershipConnection", component.GetConnString(), "System.Data.SqlClient");
                    connectionStringsSection.ConnectionStrings.Add(connTemplate);
                    config.Database.EntityFrameworkEntitiesName = efname;
                }
            }
            else
            {
                // Standard SqlServer Connection string
                providerName = component.GetProviderName;
                connString = component.GetConnString();

                ConnectionStringSettings appTemplate = new ConnectionStringSettings(config.Database.ConnectionStringName, connString, providerName);
                connectionStringsSection.ConnectionStrings.Clear();
                connectionStringsSection.ConnectionStrings.Add(appTemplate);
            }
        }
        public string GetConnString(InstallerConfig config, string dbName)
        {
            string connString = string.Empty;

            //if (config.Database.UseSqlCe40)
            //{
            //    connString = SqlCeConnection(config);
            //}
            //else
            //{
            //    // For standard connections.
            //    connString = NamedDbConnection(config, dbName);
            //}

            /* Update by King Wilder
             * Date: November 22, 2011
             * This uses the new ConnectionFactory to generate proper connection strings based
             * on the incoming parameters in the InstallerConfig object.
             */
            ConnectionFactory factory = new ConnectionFactory(config);
            connString = factory.ConnectionString();

            return connString;
        }
        public void entityframework_connection_composes_sqlconnectionstring_using_credentials()
        {
            // Arrange
            InstallerConfig config = new InstallerConfig();
            config.Database.DataSource = @"kingwilder-pc\sqlserver";
            config.Database.InitialCatalog = "BloggerApp";
            config.Database.UseTrustedConnection = false;
            config.Database.EntityFrameworkEntitiesName = "BloggerEntities";
            config.Database.UserName = "******";
            config.Database.Password = "******";

            IConnectionProvider efprovider = new EntityFrameworkConnectionString(config);

            // Act
            var actual = efprovider.GetConnectionString();
            var expected = @"metadata=res://*/Models.BloggerEntities.csdl|res://*/Models.BloggerEntities.ssdl|res://*/Models.BloggerEntities.msl;provider=System.Data.SqlClient;";
            expected += @"provider connection string=""Data Source=kingwilder-pc\sqlserver;Initial Catalog=BloggerApp;User ID=dbadminuser;Password=dbadminpassword;MultipleActiveResultSets=True;Application Name=EntityFramework""";

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void standard_sql_connection_string_with_userid_password()
        {
            // Arrange
            InstallerConfig config = new InstallerConfig();
            config.Database.DataSource = @"kingwilder-pc\sqlserver";
            config.Database.InitialCatalog = "CommerceApp";
            config.Database.UseTrustedConnection = false;
            config.Database.UserName = "******";
            config.Database.Password = "******";

            IConnectionProvider provider = new SqlConnectionString(config);

            // Act
            var actual = provider.GetConnectionString();
            var expected = @"Data Source=kingwilder-pc\sqlserver;Initial Catalog=CommerceApp;User ID=dbadminuser;Password=dbadminpassword";

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void standard_sql_connection_string_with_integrated_security()
        {
            // Arrange
            InstallerConfig config = new InstallerConfig();
            config.Database.DataSource = @"kingwilder-pc\sqlserver";
            config.Database.InitialCatalog = "BloggerApp";
            config.Database.UseTrustedConnection = true;

            ISqlConnection provider = new SqlConnectionString(config);

            // Act
            var actual = provider.GetConnectionString();
            var expected = @"Data Source=kingwilder-pc\sqlserver;Initial Catalog=BloggerApp;Integrated Security=True";

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void standard_sql_connection_string_with_all_parameters_returns_integrated_security()
        {
            // Arrange
            InstallerConfig config = new InstallerConfig();
            config.Database.DataSource = @"kingwilder-pc\sqlserver";
            config.Database.InitialCatalog = "CommerceApp";
            config.Database.UseTrustedConnection = true;
            config.Database.UserName = "******";
            config.Database.Password = "******";

            IConnectionProvider provider = new SqlConnectionString(config);

            // Act
            var actual = provider.GetConnectionString();
            var expected = @"Data Source=kingwilder-pc\sqlserver;Initial Catalog=CommerceApp;Integrated Security=True";

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #16
0
        /// <summary>
        /// Run the process to install the database and users.
        /// </summary>
        /// <param name="config"></param>
        public static void Run(InstallerConfig config)
        {
            if (config == null)
                throw new NullReferenceException("config");

            try
            {
                // Update the web.config/connectionStrings section.
                UpdateWebConfig(config);

                // Create membership roles and users.
                CreateMembership(config);

                // Now execute the sql scripts.
                RunScripts(config);

                // Now create the roles and add users.
                AddUsers(config);

                // Finally remove the AppInstalled key in the appsettings.
                RemoveAppInstalledKey();
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #17
0
        /// <summary>
        /// Write the new connection string to the web.config file and update the membership sections if necessary.
        /// </summary>
        private static void UpdateWebConfig(InstallerConfig config)
        {
            System.Configuration.Configuration configSection = WebConfigurationManager.OpenWebConfiguration("~");
            if (configSection == null)
            {
                throw new InvalidOperationException("Configuration file not available.");
            }

            IConnectionStringComponent component = new ConnectionStringComponent(config);
            IConfigurationFactory factory = new ConfigurationFactory(component);
            factory.Execute(config, configSection);

            // You can uncomment this if you want to add a LocalSqlServer connection.
            // I am connecting to the ASPNETDB tables with the same connection string since they are both in the same database.
            // If you create a separate ASPNETDB database, then you can uncomment the following and set the connection string manually.
            //ConnectionStringSettings LocalSqlServer = new ConnectionStringSettings("LocalSqlServer", component.GetConnString(), "System.Data.SqlClient");
            //ConnectionStringsSection connSection = configSection.ConnectionStrings;
            //connSection.ConnectionStrings.Add(LocalSqlServer);

            configSection.Save();

            Fix();
        }
 public ConnectionStringComponent(InstallerConfig config)
 {
     this.config = config;
 }
Пример #19
0
        /// <summary>
        /// Add users and roles inside a transaction in case there's an exception, 
        /// we can simply click the "Install" button again.
        /// </summary>
        /// <param name="config"></param>
        private static void AddUsers(InstallerConfig config)
        {
            if (config.Membership.Create)
            {
                using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
                {
                    // Now create the roles
                    foreach (var role in config.RoleManager.Roles)
                    {
                        if (!Roles.RoleExists(role.Name))
                            Roles.CreateRole(role.Name);
                        //throw new Exception("Error adding user - by King.");

                        // Now create user and add to role.
                        foreach (var user in role.Users)
                        {
                            MembershipCreateStatus status = MembershipCreateStatus.UserRejected;
                            MembershipUser u = System.Web.Security.Membership.CreateUser(user.UserName.Trim(), user.Password.Trim(), user.Email.Trim(),
                                user.SecretQuestion.Trim(), user.SecretAnswer.Trim(), true, out status);

                            if (status == MembershipCreateStatus.Success)
                            {
                                // Add user to role
                                Roles.AddUserToRole(user.UserName, role.Name);
                            }
                            else if (status == MembershipCreateStatus.DuplicateUserName)
                            {
                                // Add a duplicate username to another role.
                                // This allows the same user to be added to any number of roles.
                                try
                                {
                                    Roles.AddUserToRole(user.UserName, role.Name);
                                }
                                catch (Exception)
                                {
                                }
                            }
                            else if (status == MembershipCreateStatus.InvalidPassword)
                            {
                                throw new ApplicationException("Please update the install.config file.  The passwords don't adhere to the rules in the web.config/membership section.");
                            }
                        }
                    }
                    scope.Complete();
                }
            }
        }
Пример #20
0
 public SqlCe40ConnectionString(InstallerConfig config)
 {
     this.config = config;
 }
Пример #21
0
 private void InstallASPNETDBTables(InstallerConfig config)
 {
     string[] files = Directory.GetFiles(config.Path.AppPath + @"App_Data\scripts");
     foreach (string file in files)
     {
         string[] statements = GetScriptStatements(File.ReadAllText(file, new System.Text.UTF8Encoding()), StringSplitOptions.None);
         ExecuteStatements(statements, config);
     }
 }
Пример #22
0
 public ConnectionFactory(InstallerConfig config)
 {
     this._config = config;
 }
Пример #23
0
 public InstallerRulesValidator(InstallerConfig config)
 {
     this.config = config;
 }
Пример #24
0
        /// <summary>
        /// Create the Membership database and set the roles and users.
        /// </summary>
        /// <param name="config"></param>
        private static void CreateMembership(InstallerConfig config)
        {
            if (config.Membership.Create)
            {
                // Let's first verify that the RoleManager is enabled.
                if (!Roles.Enabled)
                    throw new ApplicationException("The RoleManager was not Enabled. It has been updated! Click &quot;Install&quot; to continue.");

                // Added: 5/19/2011 By King Wilder
                // Needed a way to validate rules based on the Membership section
                // in the web.config, such as minRequiredPasswordLength.  This
                // factory class will create rules based on these requirements and
                // validate the InstallerConfig values then display the error
                // messages back to the browser.
                System.Configuration.Configuration configSection = WebConfigurationManager.OpenWebConfiguration("~");
                IRulesValidationFactory rulesFactory = new RulesValidationFactory(config, configSection);
                if (!rulesFactory.Validate())
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<p><b>There are some items that need your attention:</b></p>");
                    sb.Append("<ul>");
                    foreach (string error in rulesFactory.ValidationErrors)
                    {
                        sb.AppendFormat("<li>{0}</li>", error);
                    }
                    sb.Append("</ul>");
                    sb.Append("<p>Please fix these issues in the installer.config file and then come back and click the &quot;Install&quot; button.</p>");

                    throw new ApplicationException(sb.ToString());
                }

                // Add the ASPNETDB tables to the database using the SqlServices Install method.
                // This will add the ASPNETDB tables to the same database as the application.
                // NOTE: This method can ONLY be used for SQL Server.  To point to MySql,
                // you will need to create the database scripts for MySql and add them to
                // the RunScripts method, but then you need to have the MySql data provider
                // set in the web.config.
                if (config.Database.UseTrustedConnection)
                {
                    // For SQL Server trusted connections
                    try
                    {
                        System.Web.Management.SqlServices.Uninstall(config.Database.DataSource.Trim(), config.Database.InitialCatalog, System.Web.Management.SqlFeatures.All);
                    }
                    catch (SqlException)
                    {
                    }

                    //DropASPNETDBTables(config);
                    System.Web.Management.SqlServices.Install(config.Database.DataSource.Trim(), config.Database.InitialCatalog, System.Web.Management.SqlFeatures.All);
                }
                else
                {
                    // For SQL Server
                    try
                    {
                        System.Web.Management.SqlServices.Uninstall(config.Database.DataSource.Trim(), config.Database.UserName, config.Database.Password, config.Database.InitialCatalog, System.Web.Management.SqlFeatures.All);
                    }
                    catch (SqlException)
                    {
                    }

                    //DropASPNETDBTables(config);
                    System.Web.Management.SqlServices.Install(config.Database.DataSource.Trim(), config.Database.UserName, config.Database.Password, config.Database.InitialCatalog, System.Web.Management.SqlFeatures.All);
                }

            }
        }
Пример #25
0
 public RulesValidationFactory(InstallerConfig config, Configuration configSection)
 {
     this._config = config;
     this._membershipSection = (MembershipSection)configSection.GetSection("system.web/membership");
 }
 public EntityFrameworkConnectionString(InstallerConfig config)
 {
     this.config = config;
 }
Пример #27
0
        public void Execute(InstallerConfig config, Configuration configSection)
        {
            UpdateConnectionString(config, configSection);

            UpdateMembershipProviders(configSection, config);
        }
Пример #28
0
 public static void UpdateConfig(InstallerConfig config)
 {
     // Update the web.config/connectionStrings section.
     UpdateWebConfig(config);
 }
Пример #29
0
        /// <summary>
        /// Update the web.config membership related config sections, membership, profile, and roleManager.
        /// And also set the roleManager Enabled property to true.
        /// </summary>
        /// <param name="configSection"></param>
        /// <param name="config"></param>
        private void UpdateMembershipProviders(Configuration configSection, InstallerConfig config)
        {
            if (config.Membership.Create)
            {
                MembershipSection membership = configSection.GetSection("system.web/membership") as MembershipSection;
                ProfileSection profile = configSection.GetSection("system.web/profile") as ProfileSection;
                RoleManagerSection roleManager = configSection.GetSection("system.web/roleManager") as RoleManagerSection;

                string connString = config.Database.ConnectionStringName;
                if (!string.IsNullOrEmpty(config.Database.EntityFrameworkEntitiesName))
                {
                    connString = "MembershipConnection";
                }

                // Update the membership section.
                bool isCustomMembershipProvider = (config.Membership.ProviderName == "AspNetSqlMembershipProvider") ? false : true;
                membership.DefaultProvider = config.Membership.ProviderName;

                for (int i = 0; i < membership.Providers.Count; i++)
                {
                    if (membership.Providers[i].Name == "AspNetSqlMembershipProvider")
                    {
                        membership.Providers[i].Parameters["connectionStringName"] = connString;
                        membership.Providers[i].Parameters["name"] = "AspNetSqlMembershipProvider";
                        membership.Providers[i].Parameters["type"] = "System.Web.Security.SqlMembershipProvider";
                        membership.Providers[i].Parameters["applicationName"] = config.ApplicationName;
                    }
                }

                if (isCustomMembershipProvider)
                {
                    // Create a new provider.
                    ProviderSettings p = new ProviderSettings();
                    p.Parameters["connectionStringName"] = connString;
                    p.Parameters["name"] = config.Membership.ProviderName;
                    p.Parameters["type"] = config.Membership.type;
                    p.Parameters["applicationName"] = config.ApplicationName;
                    membership.Providers.Add(p);
                }

                // Update the profile section.
                bool isCustomProfileProvider = (config.Profile.ProviderName == "AspNetSqlProfileProvider") ? false : true;
                profile.DefaultProvider = config.Profile.ProviderName;
                for (int i = 0; i < profile.Providers.Count; i++)
                {
                    if (profile.Providers[i].Name == "AspNetSqlProfileProvider")
                    {
                        profile.Providers[i].Parameters["connectionStringName"] = connString;
                        profile.Providers[i].Parameters["name"] = "AspNetSqlProfileProvider";
                        profile.Providers[i].Parameters["type"] = "System.Web.Profile.SqlProfileProvider";
                        profile.Providers[i].Parameters["applicationName"] = config.ApplicationName;
                    }
                }

                if (isCustomProfileProvider)
                {
                    ProviderSettings p = new ProviderSettings();
                    p.Parameters["connectionStringName"] = connString;
                    p.Parameters["name"] = config.Profile.ProviderName;
                    p.Parameters["type"] = config.Profile.type;
                    p.Parameters["applicationName"] = config.ApplicationName;
                    profile.Providers.Add(p);
                }

                // Update the roleManager section.
                bool isCustomRoleProvider = (config.RoleManager.ProviderName == "AspNetSqlRoleProvider") ? false : true;
                roleManager.DefaultProvider = config.RoleManager.ProviderName;
                for (int i = 0; i < roleManager.Providers.Count; i++)
                {
                    if (roleManager.Providers[i].Name == "AspNetSqlRoleProvider")
                    {
                        roleManager.Providers[i].Parameters["connectionStringName"] = connString;
                        roleManager.Providers[i].Parameters["name"] = "AspNetSqlRoleProvider";
                        roleManager.Providers[i].Parameters["type"] = "System.Web.Security.SqlRoleProvider";
                        roleManager.Providers[i].Parameters["applicationName"] = config.ApplicationName;
                    }
                }

                if (isCustomRoleProvider)
                {
                    ProviderSettings p = new ProviderSettings();
                    p.Parameters["connectionStringName"] = connString;
                    p.Parameters["name"] = config.RoleManager.ProviderName;
                    p.Parameters["type"] = config.RoleManager.type;
                    p.Parameters["applicationName"] = config.ApplicationName;
                    roleManager.Providers.Add(p);
                }

                roleManager.Enabled = true;
            }
        }
Пример #30
0
 /// <summary>
 /// This will execute the sql statements.
 /// </summary>
 /// <param name="tableStatements"></param>
 /// <param name="dbName"></param>
 private static void ExecuteStatements(string[] tableStatements, InstallerConfig config)
 {
     if (tableStatements.Length > 0)
     {
         using (SqlConnection conn = new SqlConnection())
         {
             // Make sure we're not returning the EntityFramework connection string.
             config.Database.EntityFrameworkEntitiesName = "";
             IConnectionStringComponent component = new ConnectionStringComponent(config);
             conn.ConnectionString = component.GetConnString();
             conn.Open();
             using (SqlCommand command = new SqlCommand(string.Empty, conn))
             {
                 foreach (string statement in tableStatements)
                 {
                     command.CommandText = statement;
                     command.ExecuteNonQuery();
                 }
             }
         }
     }
 }