Register
Tuesday, March 09, 2010
 
 DBAs And ProgrammersBlog
  
News! Minimize
   
 
 Print   
 
Misc Blog Stuff Minimize
   
 
 Print   
 
The Reluctant DBA Minimize
 
 
 
 Print   
 
Reluctant DBA Minimize
   
 
  
 
Reluctant DBA Minimize
   
 
  
 
The Reluctant DBA Minimize
 
Author:CarpDeusCreated:4/18/2008 6:56 AM
As a programmer and database administrator, I've seen a lot and here I'll record bits of information about what I'm doing and how I'm overcoming various challenges

Every now and again, you are doing something and you need a small screwdriver instead of a hammer. I've been working on a lot of repetitive API work where I end up copying a set of files, renaming them, and then editing them. While I should just write a factory to handle these things, in the meantime I wanted to simplify my rename of a batch of files. So I wrote a little console app for batch renaming (download an executable here). The whole of the code is only 60 lines and that's because I wanted to include a help. So, you can cut and paste from here if you want:

using System;using System.Collections.Generic;using System.Text;using System.IO;

namespace bRenamer{class Program{  static void Main(string[] args)  {   if (args.GetUpperBound(0) != 2)   {    System.Version AppVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;    Console.Clear();    Console.WriteLine("{4}\tVersion: {0}.{1}.{2}.{3}", AppVersion.Major.ToString(),...

Read More »

 So, I'm playing around with SQL Data Services (SDS), one of Microsoft's Cloud Databases. (see more here, signup forPublic CTP here). And it requires some shifts from the way that things are normally done. I've got a demo that I talk abouthere, but I've made some changes since then. The original demo only had one "table", a calendar of events. I've updated thatZip file to now include another "table".

Read More »

When is a UUID not a UUID? When it automagically changes case on you.

Mike Amundsen came to me with a minor gripe about being inconsistent with casing GUIDs coming from the database. He was getting lower case in the detail and upper case in the list. I didn't think I was doing that so I did a little bit of research. Microsoft, as can be the case when you're a very large company, is a bit inconsistent. According to the proposed standard (RFC-4122):

Each field is treated as an integer and has its value printed as a zero-filled hexadecimal digit string with the most significant digit first.  The hexadecimal values "a" through "f" are output as lower case characters and are case insensitive on input.

And .NET does this correctly. Put the following code into a console app.

C#

string stringControlGUID = "4A71C777-1F6E-45D5-89D5-88CCE2AAD25B";Guid guidControlGUID...

Read More »

 

Read More »

So, while the servers I run are all SQL 2005, I'm using the SQL 2008 tools for editing. Along with the inherent difficulties I find with Intellisense, there's another minor issue which turns out to be Virtual Space.

In Virtual Space mode, the Editor acts as if the space past the end of each line is filled with an infinite number of spaces, allowing code lines to continue off the side of the visible screen area. (MS Books Online)

Which means that my years of keyboard training require re-training. For instance, if I'm at the beginning of a line and want to go to the end of the previous line, hitting the left arrow key no longer works. Instead I need to hit up and then end. Also, if I click on a line and my mouse is over to the right part of the screen, my cursor ends up waiting for me to type with lots and lots of white space to the...

Read More »

I do a fair share of C# programming in my job, in addition to the database component. And I love using string.Format() to easily build strings. And I'm in the midst of a conversion project where I'm going to have a static chunk of XML that I'll need to use for every record getting converted, and string.Format comes to the rescue in an not so intuitive way. I'll build a string with the replacement tokens and use that string as the pattern for the format command. So it will look something like this:

StringBuilder XmlTemplate = new StringBuilder(""); int qID = 0; XmlTemplate.AppendFormat("[{1}]XmlTemplate.AppendFormat("[{1}]XmlTemplate.AppendFormat("[{1}]XmlTemplate.AppendFormat("[{1}]XmlTemplate.Append(""); XmlTemplate = XmlTemplate.Replace('[', '{').Replace(']', '}');

// while inside loop of conversion data string XmlToProcess = string.Format(XmlTemplate.ToString(), "first", "second", "third", "fourth"); MessageBox.Show(XmlToProcess );

The only real downside to...

Read More »

I like that SQL 2008 has Intellisense, but there are some quirks to it I don't likeneed to get used to,  namely capitalization. Take the following example:

image

If I want to use the Users table, I would normally hit the space bar. In this instance, however, Intellisense will finish the usersessionlist. Yes, C# works the same way. And yes, it will make me a better coder to actually use Users (which Intellisense interprets correctly) but there is a lot of legacy code that has no casing rhyme or reason to it and it will take some time to get used to typing correctly in SQL.

Ah well, lazy coding practices need banished.

Since SQL Server 2005 came out, it has been much easier to audit changes to the structure of the database using Database Level Triggers, like this one:

CREATE TRIGGER [Audit] ON database FOR DDL_DATABASE_LEVEL_EVENTS AS DECLARE @data XML DECLARE @cmd NVARCHAR(max) DECLARE @posttime NVARCHAR(24) DECLARE @spid NVARCHAR(6) DECLARE @loginname NVARCHAR(100) DECLARE @hostname NVARCHAR(100) SET @data = EVENTDATA() SET @cmd = @data.value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]', 'NVARCHAR(max)') SET @cmd = LTRIM(RTRIM(REPLACE(@cmd,'',''))) SET @posttime = @data.value('(/EVENT_INSTANCE/PostTime)[1]', 'NVARCHAR(24)') SET @spid = @data.value('(/EVENT_INSTANCE/SPID)[1]', 'nvarchar(6)') SET @loginname = @data.value('(/EVENT_INSTANCE/LoginName)[1]',     'NVARCHAR(100)') SET @hostname = HOST_NAME() INSERT INTO auditlog.dbo.AuditLog(Command, PostTime,HostName,LoginName, DatabaseName) VALUES(@cmd, @posttime,...

Read More »

BrentO posted about two mistakes he made as a DBA and I thought I'd share the two most unique ones from my career. The first one isn't exactly a database mistake, but I wrote a book about SQL Server 2000 for programmers called the Handbook for Reluctant Database Administrators. In the opening chapter, where I did a short history of databases, I included the following, taken from the Amazon.com Look inside feature:

RDBAError

Of course, what I meant to say was Grace Hopper, coiner of the term bug...

Read More »

It's an old problem. Let's say you want to use a ComboBox in your WinForm application and you want to have a display and a value that are separate. If you are using DataBind that's a breeze, just specify the two columns separately. But ComboBox.Items.Add() only takes an object. So, if you want to add a string to display and use that string as the value, you're all set. If you want something more then you need to create a ComboBox item object. Which isn't supplied by default. So you create one. The only good news for 2008 is that it cuts the number of lines by 2/3 because of the automagic properties syntax. Here's the class you'll need:

/// /// cbItem is a handy class for adding items to /// a ComboBox when you don't want to databind. /// public class cbItem {   ///   /// The name of the object   ///   public string Name { get; set; }

  ///   /// The value of the object   ///   public string Value { get; set; }

 ...

Read More »

 
 
 Print   
 
Privacy Statement | Terms Of Use Copyright 2001-2008 by ReluctantDBA.com