private DataConnection CreateSourceDataConnection(StorageDescriptor storageDescriptor)
        {
            var connectionString = storageDescriptor.Tenant.HasValue
                ? _connectionStringSettings.GetConnectionString(
                storageDescriptor.ConnectionStringIdentity, storageDescriptor.Tenant.Value)
                : _connectionStringSettings.GetConnectionString(
                storageDescriptor.ConnectionStringIdentity);

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new Exception($"No connection string for {storageDescriptor.ConnectionStringIdentity.GetType().Name} for tenant {storageDescriptor.Tenant} is defined");
            }

            using var scope = new TransactionScope(TransactionScopeOption.Suppress);

            // Creating connection to source that will NOT be enlisted in transactions
            var connection = CreateDataConnection(
                connectionString,
                storageDescriptor.MappingSchema,
                storageDescriptor.CommandTimeout);

            if (connection.Connection.State != ConnectionState.Open)
            {
                connection.Connection.Open();
            }

            scope.Complete();

            return(connection);
        }
Exemplo n.º 2
0
        public DataConnection CreateErmConnection()
        {
            var dataConnection = new DataConnection(
                SqlServerTools.GetDataProvider(SqlServerVersion.v2012),
                _connectionStringSettings.GetConnectionString(ErmConnectionStringIdentity.Instance, _tenantProvider.Current));

            dataConnection.AddMappingSchema(Schema.Erm);
            return(dataConnection);
        }