public static async Task CreateTablesAndStoredProceduresAsync() { var conn = ConnectionManager.GetDefaultConnection(); // Create a command object identifying the stored procedure using (var cmd = conn.CreateCommand()) { // // Set the command object so it knows to execute a stored procedure cmd.CommandType = CommandType.Text; cmd.CommandText = EmbeddedAssembly.GetFromResources("TablesAndSPsCreatorQuery.sql"); // // execute the command try { await conn.OpenAsync(); await cmd.ExecuteNonQueryAsync(); } finally { conn.Close(); } } }
public static async Task CreateDatabaseAsync() { var conn = ConnectionManager.GetDefaultConnection(); var databaseName = conn.Connection.DatabaseName; var masterConn = conn.Connection.Clone() as Connection; masterConn.DatabaseName = "master"; var sqlConn = new SqlConnection(masterConn.ConnectionString); // Create a command object identifying the stored procedure using (var cmd = sqlConn.CreateCommand()) { // // Set the command object so it knows to execute a stored procedure cmd.CommandType = CommandType.Text; cmd.CommandText = EmbeddedAssembly.GetFromResources("DatabaseCreatorQuery.sql") .Replace("#DatabaseName", databaseName); // // execute the command try { await sqlConn.OpenAsync(); await cmd.ExecuteNonQueryAsync(); } finally { sqlConn.Close(); } } }