public BannerDB() { // only load sql from xml when sqlresource is null if (_QUERIES == null) { _QUERIES = new SqlResource(HttpContext.Current.Server.MapPath(FILE_QUERIES)); } // only initialize the Banner DB when it is null if (_DB == null) { _DB = new Database(DB_BANNER); } }
private static void RunSql(SqlResource res, ref SqlConnection conn) { string sql; string name = String.Format("UnitTests.SQL.{0}.sql", res); using (Stream resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(name)) { Debug.Assert(resource != null, "Missing resource: " + name); StreamReader reader = new StreamReader(resource); sql = reader.ReadToEnd(); } SqlTransaction trans = conn.BeginTransaction(); foreach (string stmt in Splitter.Split(sql).Where(p => !String.IsNullOrWhiteSpace(p))) { SqlCommand cmd = new SqlCommand(stmt, conn, trans); if(cmd.ExecuteNonQuery() == 0) { trans.Rollback(); throw new Exception("Could not run SQL: " + res); } } trans.Commit(); }