The Daily Parker

Politics, Weather, Photography, and the Dog

D is for Database

Blogging A to ZWelcome to day 4 of the Blogging A-to-Z challenge. After yesterday's more theoretical post on the CLR, today will have a practical example of how to connect to data sources from C# applications.

Almost every application ever written needs to store data somewhere. If you're deploying a .NET website into Microsoft Azure (like this blog), you will probably connect it to an Azure SQL Database. Naturally, Visual Studio and C# make this pretty easy.

Here's the code that opens up a database connection and prints out to the Trace window what it's opened:

#region Copyright ©2018 Inner Drive Technology

using System.Configuration;
using System.Data.SqlClient;
using System.Diagnostics;

#endregion

namespace InnerDrive.DailyParkerAtoZ.WeekOne
{
	public static class DataConnections
	{
		private static string ConnectionString => ConfigurationManager.ConnectionStrings["Database"].ConnectionString;

		public static void Connect()
		{
			using (var connection = new SqlConnection(ConnectionString))
			{
				connection.Open();
				Trace.WriteLine($"Connected to {connection.DataSource}");
			}
		}
	}
}

Let's take a look at that line by line.

Lines 3-6 tell the compiler that the objects referenced in the executable code come from those four namespaces (which I'll talk more about on April 16th). The SqlConnection class, for example, lives in the System.Data.SqlClient namespace. If I didn't have the using statement on line 5, I'd have to reference the class and its namespace as System.Data.SqlClient.SqlConnection, which is cumbersome.

Line 13 creates a ConnectionString property that gets its value from a configuration setting. More on that below.

Line 17 first sets up a different kind of using statement, which makes sure that whatever the expensive SqlConnection class does while its alive, it gets cleaned up when it finishes on line 21—even if it throws an exception. Then the same line creates a new SqlConnection object and assigns it to the variable connection.

Line 19 attempts to open the connection to the database. If it succeeds, line 20 prints out the name of the data source. If it fails, it throws an exception that whatever method called this one can catch.

The configuration file looks like this (but with a real database, user ID, and password):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<connectionStrings>
		<add 
			name="Database" 
			connectionString="server={server name}.database.windows.net;initial catalog={database name};persist security info=True;user id={user ID};password={password};"
		/>
	</connectionStrings>
</configuration>

Notice that the name on line 5 corresponds to the configuration setting name on line 13 of the C# code. That's how the code knows which connection string to read from configuration.

Finally, there's also a unit test, which looks like this:

#region Copyright ©2018 Inner Drive Technology

using InnerDrive.DailyParkerAtoZ.WeekOne;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace InnerDrive.DailyParkerAtoZ.UnitTests
{
	[TestClass]
	public class DataConnectionsTests
	{
		[TestMethod]
		public void CanConnectToDataSource()
		{
			DataConnections.Connect();
		}
	}
}

If the call to DataConnections.Connect() succeeds, the test passes. If the call fails, the test fails and shows the exception that gets thrown.

You can download the code for all of these posts here. You'll have to change the configuration information in the unit test project's app.config file to make it work, of course.

C is for Common Language Runtime

Blogging A to ZDay 3 of the Blogging A-to-Z challenge brings us to the heart of .NET: the Common Language Runtime (CLR).

Microsoft defines the CLR as the run-time environment which "runs the code and provides services that make the development process easier." That isn't the most helpful definition, so let me try to elaborate.

As I described Sunday and yesterday, the .NET compiler takes your source code from C# or whatever other language you use and compiles it down to one or more managed modules containing intermediate language (IL), which get further compiled into assemblies.

When your program runs, the CLR is the thing running it. It loads your assemblies and then handles all the tasks your program needs to survive, like memory management, thread synchronization, exception handling, security, etc. It actually does this through Just-in-Time compilation (JIT), when it translates the IL into your machine's own language. This means that when an IL instruction is executed for the second time, it runs in native CPU code.

The CLR also manages .NET's common type system (CTS), which "defines how types are declared, used, and managed in the common language runtime," according to Microsoft. Types (my topic for April 23rd) are therefore a part of every .NET program, even (gasp!) Ruby.NET. I'm picking on Ruby because in that language, ever instruction gets interpreted at run time, making it possible to use types that you haven't defined. The CLR and the CTS prevent you from doing that.

To learn a lot more about the CLR, I strongly recommend Jeffrey Richter's CLR via C#, which I mentioned Sunday.

We're #11?

Crain's reported yesterday on the latest business-school rankings from US News and World Report. University of Chicago tied with Harvard at the top spot and Northwestern landed at #6:

The magazine labels its ranking a year in advance, so this is the 2019 list. While it started the rankings in 1990, it has historical data reaching back only to 1994, but it was confident this was the first No. 1 showing for Booth.

“The University of Chicago’s Booth School of Business tied for No. 1 this year due to its strong placement data, meaning it had the highest percentage of employed students at graduation and, among the very top ranked schools, the highest percentage of graduates employed three months after graduation,” Robert Morse, the magazine’s chief data strategist, said in a statement. “The mean starting salary and bonus of Booth graduates was one of the highest among top schools.”

Duke dropped to #11 in the full-time rankings, but stayed at #5 in the Executive MBA list.

I expect they care more about this in Durham than I do here in Chicago.

No more daily PE in Illinois

For my entire school life, from Kindergarten to 12th grade, I had daily gym class. In 1957, Illinois became the first state to require all kids to have daily PE. This was the case until this school year:

The law cuts daily PE to a minimum of three days per week and, starting in seventh grade, students involved in interscholastic or extracurricular athletic programs could skip PE. Those moves and more were touted as a way to save money, but some fear the changes will push PE to the back burner of the curriculum lineup, even as physical education has been supported by public officials, including former first lady Michelle Obama, as a way to combat childhood obesity.

In the Illinois Report Card data released each year, the Illinois State Board of Education notes that 60 minutes of physical activity per day can improve academics and prevent childhood obesity, diabetes and heart disease. “For students of all ages, physical education provides opportunities to learn motor skills, develop fitness, build team skills, strengthen problem solving abilities, and learn about healthy lifestyles,” ISBE said.

In fact, there has been confusion in various districts about aspects of the new law and whether districts are pursuing waivers correctly.

This fall, Champaign Community Unit School District 4 was moving to get a new five-year waiver to allow ninth- and 10th-graders to skip PE during the time they were involved in an interscholastic sport.

The waiver was withdrawn because it was no longer necessary based on a new provision in the PE law: Now, seventh- through 12th-graders may be excused from PE if they participate in interscholastic or extracurricular athletic programs. The law previously allowed only high school juniors and seniors to be excused under those circumstances.

Meanwhile, administrators in several high school districts told the Tribune they don’t plan to reduce their usual five days of PE, in part because of the complicated scheduling of high school classes as well as the potential difficulties of eliminating full-time PE teachers.

It seems like this change to the law wasn't well thought-out, wasn't well publicized, and wasn't particularly effective. Welcome to Illinois. I'm going to try to find out how my state rep and senator voted on this thing.

The Angriest Librarian

An MLS student in Portland, Ore., wants you to understand that even though you don't personally use them, libraries are thriving:

Today, depending on the community they serve, a public librarian is part educator, part social worker, and part Human Google. What they aren’t is a living anachronism, an out-of-touch holdout in a dying job who’s consigned to a desk, scolding kids for returning books a few days late.

An urban librarian in a struggling neighborhood, like Chera Kowalski in Philadelphia’s Kensington, is just as likely to be saving lives by giving Narcan to overdosed patrons as she is to be recommending a new Young Adult series. The new model of librarianship is about embracing more than just books—it’s about making a positive impact on the lives of patrons. My liberal use of the word “motherfucker” may have been the most popular aspect of my Twitter rant, but the most important was my message to LGBT teens, and to immigrants, and to the homeless and poor: The library is a safe place for you to come and get what you need.

Someone asked me why I got into libraries. My answer—though I’ve been “into” libraries my whole life—was simple: I believe in reducing barriers to better outcomes for marginalized and underserved populations, motherfucker.

Mazel tov.

The Mindset List, class of 2021

Today is my birthday, which makes this year's Beloit College Mindset List even harder to read:

Students heading into their first year of college this year are mostly 18 and were born in 1999.

2. They are the last class to be born in the 1900s, the last of the Millennials --  enter next year, on cue, Generation Z!

11. The Panama Canal has always belonged to Panama and Macau has been part of China.

12. It is doubtful that they have ever used or heard the high-pitched whine of a dial-up modem.

16. They are the first generation to grow up with Watson outperforming Sherlock.

25. By the time they entered school, laptops were outselling desktops.

38. They have only seen a Checker Cab in a museum.

47. The BBC has always had a network in the U.S. where they speak American.

59. Bill Clinton has always been Hillary Clinton’s aging husband.

Ouch.

Dev Bootcamp shutting down

The Tribune reported yesterday that Dev Bootcamp, an immersive software-development school, is shutting down after their next class graduates in December:

Dev Bootcamp’s final cohort will start classes this month and graduate in December. Campuses officially close on Dec. 8, according to the email, signed by Dev Bootcamp President Tarlin Ray. Graduating students will also get “at least six months of career support,” the letter said.

“(D)espite tremendous efforts from a lot of talented people, we’ve determined that we simply can’t achieve a sustainable business model without compromising our mission of delivering a high-quality coding education that is accessible to a diverse population of students,” the letter said.

Dev Bootcamp was never profitable, Nishimura said. The Kaplan acquisition [in 2014] gave Dev Bootcamp flexibility, but ultimately, faced with the prospect of cutting back full-time instructors and raising tuition, the company decided to shut down.

I have four co-workers who have ties to Dev Bootcamp, including one who wrote parts of the curriculum. They report that Kaplan's aggressive expansion into markets outside Chicago and San Francisco drew resources away from existing programs, driving students and faculty away. For example, one intriguing offering, "Engineering Empathy," which sought to teach budding coders how to work on teams and with clients, got cut during the rapid-expansion phase.

The three alumni in my office are some of the best coders I've ever met. So I'm sorry to see Dev Bootcamp go. I hope that in future someone creates a program as effective as theirs.

Narcissist in chief

President Trump met with the 2017 state Teachers of the Year yesterday, and, as usual, made the event all about himself:

Usually, the National Teacher of the Year speaks. This year, that didn’t happen. Usually, the president spends some time talking with the teachers, giving many of them individual attention. That barely happened Wednesday, according to several participants who agreed to speak only on the condition of anonymity because they said they fear Trump addressing them on Twitter or press secretary Sean Spicer bringing them up at a daily briefing. Usually family members join the winners to meet the president. This time few were allowed — and relatives of the teachers, some who had traveled at their own expense for many hours to attend, were left to wait in a building near the White House, with, as one said, “no water in the hot rooms.”

Rather than a ceremony in the East Room or the Rose Garden, as past presidents have done, Trump invited the teachers into the Oval Office, where he asked them all to gather around him, standing, while he sat at his desk. In the crowd were first lady Melania Trump, Vice President Pence, second lady Karen Pence and Education Secretary Betsy DeVos. It was the first lady’s birthday, and the teachers sang “Happy Birthday” to her.

In the Oval Office, with the teachers and others standing around him, Trump spoke about the teachers and engaged with a few of them (see video above), and briefly singled out the 2017 National Teacher of the Year, Sydney Chaffee, from Codman Academy Charter Public School in Dorchester, Mass. A ninth-grade teacher, she is the first national winner from a charter school in the program’s 65-year history....

How interesting that Education Secretary Betsy DeVos, who has financial stakes in charter schools, oversaw an event where a charter-school teacher won a major honor from her boss? And Trump still couldn't be gracious about it.

Read the rest of the article for how Presidents Obama and G.W. Bush honored the teachers, and ponder how often Trump will, over the next 1,362 days

Betsy DeVos behaving as predicted

When you have someone with the background, education, and beliefs of Education Secretary Betsy DeVos, you know you're not going to get any policies that benefit education. Sure enough, yesterday she started rolling back reforms begun under the Obama administration that tried to correct the abuses of the student loan industry:

The former president's administration issued a pair of memorandums last year requiring that the government's Federal Student Aid office, which services $1.1 trillion in government-owned student loans, do more to help borrowers manage, or even discharge, their debt.

But in a memorandum to the department's student aid office, DeVos formally withdrew the two Obama memos. The Obama administration's approach, DeVos said, was inconsistent and full of shortcomings. She didn't detail how the moves fell short, and her spokesmen, Jim Bradshaw and Matthew Frendewey, didn't immediately respond to a request for comment.

DeVos' move "will certainly increase the likelihood of default," said David Bergeron, a senior fellow at the Center for American Progress, a Washington think tank with close ties to Democrats, who previously worked under Democratic and Republican administrations during his more than 30 years at the Education Department before retiring as the head of postsecondary education.

It's an absolute scandal that student loans, which are some of the safest investments a bank can make because they can't be discharged in bankruptcy, have high interest rates and a history of predatory collection practices. DeVos has investments in the for-profit education companies that benefit directly from this situation. And people wonder why the Republican Party has a reputation for screwing the disadvantaged in favor of rich businesses.