Friday, August 24, 2012

Windows 8 – what’s all the fuss about?

I’d read a lot about what a bad OS Windows 8 is for desktop systems, since it’s all about adding features for use on tablets. So being the masochist I am, I thought I’d install it on my desktop machine, a none too modern Dell box with a couple of monitors. Several hours later, it was done and I hit my first problem. Windows didn’t like my mouse. This made navigating round the new user interface a little tricky. But after swapping out the mouse for another one, things got better.

So the big complaint about Windows 8 is that the Start button is no more. But move the mouse to the bottom left of the screen and a little Start popup appears. Click on that and most of your apps are listed. For the ones that aren’t, just start typing and a list of matching apps appear. And here’s the important thing about that search facility, it’s much faster than the same search functionality in Windows 7, which always seemed to hang for seconds before doing anything. The learning curve for this was about 5 minutes, although I have to admit I do occasionally mistakenly click on the task bar rather than the Start popup.

So the biggest issue seems to be a non issue, for me at least. The things that I like so far are much faster boot times, a task bar that stretches across multiple monitors and a much improved Task Manager. Nothing revolutionary but welcome none the less.

I then installed it on my laptop. Much the same experience, although Minecraft no longer runs due to my graphics card driver not supporting OpenGL. I am not popular with my daughter.

There are shedloads of new things in that Start screen, but as a desktop user I was more concerned about getting to all the stuff I currently use and that all works fine. So what’s all the fuss about?

Thursday, August 09, 2012

Executing multiple SQL statements against multiple databases

In my day job, each of the customers running in our hosted environment have their own SQL Server database. As we develop the software that runs on top of these databases, we often need to update the schema of each database. I knocked together a little console application in C# to do the job and here are the interesting parts of it. First, we need to get a list of the available databases, which can be achieved quite easily.

      List<string> DBs = new List<string>();
      // get list of available databases
      SqlCommand command = conn.CreateCommand();
      command.CommandText = "select * from master.sys.databases where DataBase_ID > 4";
      using (SqlDataReader reader = command.ExecuteReader())
      {
        while (reader.Read())
        {
          DBs.Add(reader.GetString(0));
        }
      }
      DBs.Sort();

Next, we need to execute the SQL updates. This isn’t quite as easy as you’d think. If you want to execute multiple SQL statements with GO statements between them, SqlCommand.ExecuteNonQuery won’t handle them. Fortunately SQL Server comes with some assemblies that solve the problem. So you need to add references to Microsoft.SqlServer.ConnectionInfo.dll, Microsoft.SqlServer.Management.Sdk.Sfc.dll and Microsoft.SqlServer.Smo.dll. Once they have been referenced, the following code should be able to handle any SQL you throw at it.

      foreach (string database in DBs)
      {
        Microsoft.SqlServer.Management.Smo.Server server = 
          new Microsoft.SqlServer.Management.Smo.Server(new ServerConnection(conn));
        server.ConnectionContext.ExecuteNonQuery("USE " + database + "\nGO\n" + sql);
      }