public static void RecreateDatabase(string dbName, SqlConnectionString connectionString) { var masterConnection = new SqlConnectionManager(connectionString.GetMasterConnection()); DropDatabaseTask.DropIfExists(masterConnection, dbName); CreateDatabaseTask.Create(masterConnection, dbName); }
void RecreateDatabase(string dbName, SqlConnectionString connectionString) { var masterConnection = new SqlConnectionManager(connectionString.CloneWithMasterDbName()); DropDatabaseTask.DropIfExists(masterConnection, dbName); CreateDatabaseTask.Create(masterConnection, dbName); }
static void Preparation() { SqlConnectionManager masterConnection = new SqlConnectionManager("Data Source=.;Integrated Security=false;User=sa;password=reallyStrongPwd123"); DropDatabaseTask.DropIfExists(masterConnection, "demo"); CreateDatabaseTask.Create(masterConnection, "demo"); SqlConnectionManager dbConnection = new SqlConnectionManager("Data Source=.;Initial Catalog=demo;Integrated Security=false;User=sa;password=reallyStrongPwd123"); CreateTableTask.Create(dbConnection, "OrderTable", new List <TableColumn>() { new TableColumn("Id", "INT"), new TableColumn("Item", "NVARCHAR(200)"), new TableColumn("Quantity", "INT"), new TableColumn("Price", "MONEY") }); }
static void Main(string[] args) { //Set up the connection manager to master var masterConnection = new SqlConnectionManager("Data Source=localhost;User Id=sa;Password=YourStrong@Passw0rd;"); //Recreate database DropDatabaseTask.DropIfExists(masterConnection, "demo"); CreateDatabaseTask.Create(masterConnection, "demo"); //Get connection manager to previously create database var dbConnection = new SqlConnectionManager("Data Source=localhost;User Id=sa;Password=YourStrong@Passw0rd;Initial Catalog=demo;"); //Create destination table CreateTableTask.Create(dbConnection, "Table1", new List <TableColumn>() { new TableColumn("ID", "int", allowNulls: false, isPrimaryKey: true, isIdentity: true), new TableColumn("Col1", "nvarchar(100)", allowNulls: true), new TableColumn("Col2", "smallint", allowNulls: true) }); //Create dataflow for loading data from csv into table CsvSource <string[]> source = new CsvSource <string[]>("input.csv"); RowTransformation <string[], MyData> row = new RowTransformation <string[], MyData>( input => new MyData() { Col1 = input[0], Col2 = input[1] } ); DbDestination <MyData> dest = new DbDestination <MyData>(dbConnection, "Table1"); //Link components & run data flow source.LinkTo(row); row.LinkTo(dest); source.Execute(); dest.Wait(); //Check if data exists in destination SqlTask.ExecuteReader(dbConnection, "Read all data from table1", "select Col1, Col2 from Table1", col1 => Console.WriteLine(col1.ToString() + ","), col2 => Console.WriteLine(col2.ToString())); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); }
static void Preparation() { //Recreate database if it doesn't exist SqlConnectionManager masterConnection = new SqlConnectionManager("Data Source=localhost;User Id=sa;Password=YourStrong@Passw0rd;"); DropDatabaseTask.DropIfExists(masterConnection, "demo"); CreateDatabaseTask.Create(masterConnection, "demo"); SqlConnectionManager dbConnection = new SqlConnectionManager("Data Source=localhost;User Id=sa;Password=YourStrong@Passw0rd;Initial Catalog=demo;"); //Create destination table CreateTableTask.Create(dbConnection, "OrderTable", new List <TableColumn>() { new TableColumn("Id", "INT", allowNulls: false, isPrimaryKey: true, isIdentity: true), new TableColumn("Item", "NVARCHAR(50)"), new TableColumn("Quantity", "INT"), new TableColumn("Price", "DECIMAL(10,2)") }); }
public void DropIfExists(IConnectionManager connection) { //Arrange string dbName = "ETLBox_" + TestHashHelper.RandomString(10); DropDatabaseTask.DropIfExists(connection, dbName); CreateDatabaseTask.Create(connection, dbName); bool existsBefore = IfDatabaseExistsTask.IsExisting(connection, dbName); //Act DropDatabaseTask.DropIfExists(connection, dbName); //Assert bool existsAfter = IfDatabaseExistsTask.IsExisting(connection, dbName); Assert.True(existsBefore); Assert.False(existsAfter); }
static void Main(string[] args) { var masterConnection = new SqlConnectionManager("Data Source=.;Integrated Security=false;User=sa;password=reallyStrongPwd123"); DropDatabaseTask.DropIfExists(masterConnection, "demo"); CreateDatabaseTask.Create(masterConnection, "demo"); var dbConnection = new SqlConnectionManager("Data Source=.;Initial Catalog=demo;Integrated Security=false;User=sa;password=reallyStrongPwd123"); CreateTableTask.Create(dbConnection, "Table1", new List <TableColumn>() { new TableColumn("ID", "int", allowNulls: false, isPrimaryKey: true, isIdentity: true), new TableColumn("Col1", "nvarchar(100)", allowNulls: true), new TableColumn("Col2", "smallint", allowNulls: true) }); CsvSource <string[]> source = new CsvSource <string[]>("input.csv"); RowTransformation <string[], MyData> row = new RowTransformation <string[], MyData>( input => new MyData() { Col1 = input[0], Col2 = input[1] }); DbDestination <MyData> dest = new DbDestination <MyData>(dbConnection, "Table1"); source.LinkTo(row); row.LinkTo(dest); source.Execute(); dest.Wait(); SqlTask.ExecuteReader(dbConnection, "Read all data from table1", "select Col1, Col2 from Table1", col1 => Console.WriteLine(col1.ToString() + ","), col2 => Console.WriteLine(col2.ToString())); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); }