Beispiel #1
0
        public SqlServerSlugStore(string nameOrConnectionString, SqlServerSlugStoreOptions options = null)
        {
            if (options == null)
            {
                options = new SqlServerSlugStoreOptions();
            }

            _options = options;

            if (nameOrConnectionString == null)
            {
                throw new ArgumentNullException("nameOrConnectionString");
            }

            if (IsConnectionString(nameOrConnectionString))
            {
                _connectionString = nameOrConnectionString;
            }
            else if (IsConnectionStringInConfiguration(nameOrConnectionString))
            {
                _connectionString = ConfigurationManager.ConnectionStrings[nameOrConnectionString].ConnectionString;
            }
            else
            {
                throw new ArgumentException($"Could not find connection string with name '{nameOrConnectionString}' in application config file");
            }

            Installer.InstallSqlTable(_connectionString, _options);
        }
Beispiel #2
0
        public static void InstallSqlTable(string connectionString, SqlServerSlugStoreOptions options)
        {
            var script = GetStringResource(typeof(SqlServerSlugStore).Assembly, "SlugStar.SqlServer.Install.sql");

            //do replaces
            script = script.Replace("$(SCHEMA_NAME)", options.TableSchema);
            script = script.Replace("$(TABLE_NAME)", options.TableName);

            using (var connection = new SqlConnection(connectionString))
            {
                for (var i = 0; i < 5; i++)
                {
                    try
                    {
                        connection.Execute(script);
                        break;
                    }
                    catch (SqlException ex)
                    {
                        if (ex.ErrorCode == 1205)
                        {
                            Trace.WriteLine("Deadlock occurred during automatic migration execution. Retrying...");
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }