Exemple #1
0
        public Task GetTestSqlConnection()
        {
            try
            {
                var factoryName      = GetStringQueryString("factoryName");
                var connectionString = new StreamReader(HttpContext.Request.Body).ReadToEnd();
                RelationalDatabaseWriter.TestConnection(factoryName, connectionString);
                NoContentStatus();
            }
            catch (Exception ex)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; // Bad Request

                if (Logger.IsInfoEnabled)
                {
                    Logger.Info("Error occurred during sql replication connection test", ex);
                }

                using (ContextPool.AllocateOperationContext(out JsonOperationContext context))
                {
                    using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    {
                        context.Write(writer, new DynamicJsonValue
                        {
                            ["Error"]     = "Connection failed",
                            ["Exception"] = ex.ToString()
                        });
                    }
                }
            }

            return(Task.CompletedTask);
        }
Exemple #2
0
        public SqlEtlTestScriptResult RunTest(DocumentsOperationContext context, IEnumerable <SqlTableWithRecords> toWrite, bool performRolledBackTransaction)
        {
            var summaries = new List <TableQuerySummary>();

            if (performRolledBackTransaction)
            {
                try
                {
                    using (var writer = new RelationalDatabaseWriter(this, Database))
                    {
                        foreach (var records in toWrite)
                        {
                            var commands = new List <DbCommand>();

                            writer.Write(records, commands, CancellationToken);

                            summaries.Add(TableQuerySummary.GenerateSummaryFromCommands(records.TableName, commands));
                        }

                        writer.Rollback();
                    }
                }
                catch (Exception e)
                {
                    Statistics.RecordLoadError(e.ToString(), documentId: null, count: 1);
                }
            }
            else
            {
                var simulatedWriter = new RelationalDatabaseWriterSimulator(Configuration);

                foreach (var records in toWrite)
                {
                    var commands = simulatedWriter.SimulateExecuteCommandText(records, CancellationToken).Select(x => new TableQuerySummary.CommandData
                    {
                        CommandText = x
                    }).ToArray();

                    summaries.Add(new TableQuerySummary
                    {
                        TableName = records.TableName,
                        Commands  = commands
                    });
                }
            }

            return(new SqlEtlTestScriptResult
            {
                TransformationErrors = Statistics.TransformationErrorsInCurrentBatch.Errors.ToList(),
                LoadErrors = Statistics.LastLoadErrorsInCurrentBatch.Errors.ToList(),
                SlowSqlWarnings = Statistics.LastSlowSqlWarningsInCurrentBatch.Statements.ToList(),
                Summary = summaries
            });
        }
Exemple #3
0
        protected override void LoadInternal(IEnumerable <SqlTableWithRecords> records, JsonOperationContext context)
        {
            using (var writer = new RelationalDatabaseWriter(this, Database))
            {
                foreach (var table in records)
                {
                    var stats = writer.Write(table, null, CancellationToken);

                    LogStats(stats, table);
                }

                writer.Commit();
            }
        }
Exemple #4
0
 public Task <HttpResponseMessage> TestSqlReplicationConnection(string factoryName, string connectionString)
 {
     try
     {
         RelationalDatabaseWriter.TestConnection(factoryName, connectionString);
         return(GetEmptyMessageAsTask(HttpStatusCode.NoContent));
     }
     catch (Exception ex)
     {
         return(GetMessageWithObjectAsTask(new
         {
             Error = "Connection failed",
             Exception = ex
         }, HttpStatusCode.BadRequest));
     }
 }
Exemple #5
0
        public SqlEtlSimulationResult Simulate(SimulateSqlEtl simulateSqlEtl, DocumentsOperationContext context, IEnumerable <SqlTableWithRecords> toWrite)
        {
            var summaries = new List <TableQuerySummary>();

            if (simulateSqlEtl.PerformRolledBackTransaction)
            {
                using (var writer = new RelationalDatabaseWriter(this, Database))
                {
                    foreach (var records in toWrite)
                    {
                        var commands = new List <DbCommand>();

                        writer.Write(records, commands, CancellationToken);

                        summaries.Add(TableQuerySummary.GenerateSummaryFromCommands(records.TableName, commands));
                    }

                    writer.Rollback();
                }
            }
            else
            {
                var simulatedwriter = new RelationalDatabaseWriterSimulator(Configuration);

                foreach (var records in toWrite)
                {
                    var commands = simulatedwriter.SimulateExecuteCommandText(records, CancellationToken).Select(x => new TableQuerySummary.CommandData
                    {
                        CommandText = x
                    }).ToArray();

                    summaries.Add(new TableQuerySummary
                    {
                        TableName = records.TableName,
                        Commands  = commands
                    });
                }
            }

            return(new SqlEtlSimulationResult
            {
                LastAlert = Statistics.LastAlert,
                Summary = summaries
            });
        }
        public static object GetParameterValue(DbParameter param)
        {
            var paramterValue = param.Value;

            if (paramterValue == DBNull.Value)
            {
                paramterValue = "NULL";
            }
            else if (param.DbType == DbType.AnsiString || param.DbType == DbType.String)
            {
                paramterValue = $"'{RelationalDatabaseWriter.SanitizeSqlValue(paramterValue.ToString())}'";
            }
            else if (param.DbType == DbType.Binary)
            {
                paramterValue = "<binary_data>";
            }

            return(paramterValue);
        }
Exemple #7
0
        protected override int LoadInternal(IEnumerable <SqlTableWithRecords> records, DocumentsOperationContext context)
        {
            var count = 0;

            using (var writer = new RelationalDatabaseWriter(this, Database))
            {
                foreach (var table in records)
                {
                    var stats = writer.Write(table, null, CancellationToken);

                    LogStats(stats, table);

                    count += stats.DeletedRecordsCount + stats.InsertedRecordsCount;
                }

                writer.Commit();
            }

            return(count);
        }
        public Task GetTestSqlConnection()
        {
            try
            {
                var factoryName      = GetStringQueryString("factoryName");
                var connectionString = new StreamReader(HttpContext.Request.Body).ReadToEnd();
                RelationalDatabaseWriter.TestConnection(factoryName, connectionString);

                DynamicJsonValue result = new DynamicJsonValue
                {
                    [nameof(NodeConnectionTestResult.Success)] = true,
                };

                using (ContextPool.AllocateOperationContext(out JsonOperationContext context))
                    using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    {
                        context.Write(writer, result);
                    }
            }
            catch (Exception ex)
            {
                if (Logger.IsInfoEnabled)
                {
                    Logger.Info("Error occurred during sql replication connection test", ex);
                }

                using (ContextPool.AllocateOperationContext(out JsonOperationContext context))
                {
                    using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    {
                        context.Write(writer, new DynamicJsonValue
                        {
                            [nameof(NodeConnectionTestResult.Success)] = false,
                            [nameof(NodeConnectionTestResult.Error)]   = ex.ToString()
                        });
                    }
                }
            }

            return(Task.CompletedTask);
        }