Register
Thursday, March 11, 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

I've been working on improving a stored procedure. In most instances, it runs fairly quickly but I've encountered one situation where it takes about a minute and a half to run.

And it appears that part of the problem is using table variables. So, I am working on changing some of them to more flexible temporary tables. Which isn't bad but I have a multi-statement table valued function which I use, and you can't use temporary tables in a function.

So I pull the function apart and rewrite it as a sproc using a temporary table. And this is where the first lie comes from. The function and sproc both parse a section of XML passed in. While the execution plan lies about the cost of multi-statement table functions, placing this into a stored procedure gave me my first strange reading of the day.

Parsing the XML using SELECT tbl.col.value('@AttributeShortName', 'nvarchar(256)') shortname FROM @SearchXML2.nodes('//Search') tbl(col) led to the execution plan telling me that this statement took 75% of...

Read More »

In response to a couple of request, the source code for the UUID Validity can be downloaded from my SVN instance.  Point your tortoise to https://fserv-web.finsel.com:8443/svn/PublicSource/NET/Testing/TestGuidValidation/ with a user of Public and no password.

Well, that really depends on how the input comes in. But if you need to validate whether a string is a UUID, there are a couple of ways to do that.

First is by trying to convert the string to a UUID and catching the error.

 private bool IsValidGUID(string GUIDCheck)   {    bool retVal = false;    try  to convert the string to a guid    {     Guid g = new Guid(GUIDCheck);      We successfully converted it, return true     retVal = true;    }    catch (System.FormatException)   The string was not in a GUID format    { retVal = false; }    catch (Exception ex)  Something else went wrong, let the caller figure it out    { throw ex;  }    return retVal;   }

The downside to this is that throwing errors can be expensive. A better version is to RegEx it (original source, Andrew Gunn), simplified here:

private bool IsValidGUID(string GUIDCheck)   {    if (!string.IsNullOrEmpty(GUIDCheck))    {     return new Regex(@"^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$").IsMatch(GUIDCheck);...

Read More »

I will be at VS Live Dallas giving a talk on Implementing Caching Technology as One Rung of the Scalability Ladder on December 11.

As every application grows, it reaches a point where the original design causes bottlenecks that are apparent with a thousand users that weren't with a few hundred. One method of improving scalability is to implement caching. Microsoft has taken steps toward making caching easier with Velocity, a distributed in-memory application cache platform.In this presentation we'll take a look at what caching is and what caching isn't, and then we'll explore what Velocity offers to help relieve those bottle necks. Finally we'll take a hands-on approach, working through an implementation of caching by determining what should and shouldn't be cached, looking at some caching invalidation schemes, defining and handling cache stampedes and more. When we're done you'll have several implementable steps with code samples that can use to dramatically improve your application's scalability....

Read More »

The two most difficult problems in computer science are supposed to be Naming and Cache Invalidation. But, as my friend and co-worker Mike Amundsen and I have postulated, when it comes to web development the third difficult problem is escaped characters.

HTML is filled with instructions that are set off by . So, if I wanted to indent a section of text:

Like this text is

I need to put it in a set of tags. But, in order for you to see the tag with the angle brackets and not have it interpreted as an instruction to indent tags by your browser, I need to put either <blockquote> or <blockquote>. Which both will show up as , because < and < are instructions to the browser to render the really need to use &#60;.

Confused? Add in XML which may contain something like "The telegraph giant, AT&T" which may or may not need to be preserved and  you can get into some right, royal messes. So you can escape every & sign but if the & is in front of an amp; then you'll end up with output that looks like AT&T when you wanted AT&T.

...

Read More »

One of the stated goals of Microsoft is that they make the plumbing easier for programmers. Rather than forcing us to build the intricate foundations, they provide tools like ADO.NET to make connecting to a database and manipulating/retrieving data a piece of cake.

Sometimes, however, you can encounter a problem that's beyond your ability to control because MS is being helpful.

I've got a very simple application. It's making a ADO.NET call to the database to execute a stored procedure. Occasionally, this times out. Now, you can tell me that the database was busy or there were blocking transactions or any number of other things, but I'll tell you the weren't happening. In fact, you could turn Profiler on and see the call being made from ADO.NET, see it taking an ungodly amount of disk reads and 30+ seconds.  Consistently for a set of parameters.

Now, while the web page is spinning and waiting for a timeout, run the exact set of code in Query Analyzer. Runs in milliseconds, the way it should...

Read More »

I've had a version of the Cipher Sovler on the web for years. Now I have ported that to the Windows Mobile platform as well.

Simple? Yes. But ever so enjoyable. You can download a trial version here. It  is remarkably similar to the web version, though scaled down to a much smaller screen size. This mean separating the functionality into three separate tabs. One to solve the puzzle:



One to Enter the puzzle:



And one for the statistics:



 

I need to see about setting it to change size and shape for auto-rotation and adding a time but that's for next week.

Read More »

I've been playing around with writing a little application for my handheld, a version of the cipher solver on my personal site. And, to make it more interesting, I wanted to be able to see how long it took me to solve each puzzle. Not finding a good class to use, I wrote one myself using the TimeSpan class.

Let's first look at the global variables:

///  /// Starting time  ///  DateTime startingTimer;  ///  /// Total Ticks processed  ///  Int64 totalTicks = 0;  ///  /// Is the stopwatch currently running  ///  public bool TimerRunning = false;

I think they are all fairly self-explanatory.

Now, the simple mechanics of starting and stopping the timer. There are four methods: StartTimer(), StopTimer(), PauseTimer() and RestartTimer(). The only difference between StartTimer() and RestartTimer() is that StartTimer() sets the totalTicks to 0. PauseTimer() actually just calls StopTimer(), which adds to the running tick count in totalTicks.

///  ///...

Read More »

An Universally Unique Identifier (UUID) can be a handy thing to use. They are guaranteed to be unique across time and space (or very nearly so) and make great identifiers that you can be fairly sure won't be duplicated in another table like an Identity column can. But they do pose some challenges.

Empty UUIDs, for instance. C# can use Guid.Empty.ToString() to return 00000000-0000-0000-0000-000000000000. But it can be a pain having to type that out. So it's easy to create a UDF that will return an empty UUID:

-- ============================================= -- Author:        Josef Finsel -- Create date: 6/18/20008 -- Description:    Return a zero filled UUID -- ============================================= CREATE FUNCTION EmptyUUID () RETURNS UniqueIdentifier AS BEGIN     RETURN convert(uniqueidentifier,  '00000000-0000-0000-0000-000000000000') END GO

However, I try not to use this in my actual code (see Why Functions Can Be Bad...

Read More »

I've learned many tricks over the years for dealing with dates in SQL Server. Today, one of my fellow developers came up to me and asked me how to handle string concatenation and, as it turned out, what he was trying to do was to get yesterday's date for filtering.

Fortunately, this is something I've done a time or two before so I showed him this quick trick:

select convert(datetime,convert(char(10),getdate()-1,101))

The innermost conversion changes the date to a truncated string of MM/DD/YYYY, which conviently removes any time and resets the date to Midnight. GetDate()-1 subtracts one day, another handy feature. Finally, just because SQL Server would do it itself but not necessarily as efficiently, convert the string to a date time. Which effectively changes 6/10/2008 16:08 to 6/10/2008.

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