As technical people in a field that is expanding daily, we all run into areas that we know poorly, or haven’t been able to refresh our knowledge on this decade. For me, and I’m sure many of you, SEO is one of those topics that fell by the wayside. Sure, I remember circa-1998 tips on getting the search engines to rank your site more highly, such as making sure my meta tags are filled in, using terms frequently that you want to attach to your key search values, even trying to keep the content-to-crap ratio as high as possible. But no one is paying me high dollar to come improve their site rankings, so it is obvious I was missing a few steps.
This is an archive of the posts published to LessThanDot from 2008 to 2018, over a decade of useful content. While we're no longer adding new content, we still receive a lot of visitors and wanted to make sure the content didn't disappear forever.
Asynchronous work flows are a very powerful tool in programming. They allow your threads to do other work while you wait for results from a long running piece of work. How would you write an asynchronous work flow in C#? Logically you might consider chaining together callbacks. <span class="MT_blue">new</span> Client().Connect(settings, (c1, ex1) => { <span class="MT_green">// prepare data to send</span> c.Send(sendData1, (c2, ex2) => { c2.Receive((c3, dt1, ex3) => { <span class="MT_green">// parse data and prepare response</span> c3.Send(sendData2, (c4, ex4) => { c4.Disconnect((c5, ex5) => { c5.Dispose(); }); }); }); }); }); There is a good reason you never see code like this. For one, it is highly indented and this makes it a bit awkward to read. More importantly, this approach puts your code at risk of a great deal of name conflicts, as the compiler will create a closure for each lambda and capture all of the values in the previous levels. This means you have to come up with a different name for the parameters in each lambda. Resolving this issue could involve creating an additional class to contain the necessary methods, potentially complicating a task that seems like it should be simple. This is where F# asynchronous work flows come to play.
Chaos or order? Managing objects in large and small installations of SQL Server can be a job in itself at times. In particular, for the DBA, objects we create on the instances we manage more often than not are found littered over the user and system databases. These objects more often are found in the master database in SQL Server. Really, why not put them there? We are the “masters” over the database server right? SSMS has this quality to it that when we connect to it, we get the master database glaring us in the face by default just like a booby. So of course that means we create our objects there. Right?
Today I saw someone asked a question in MSDN t-sql forums “How to calculate the number of working days between two given dates”. I found this very interesting, since we can solve this problem by using a very simple and methodical approach and by using an unorthodox approach. I will explain both the approaches. **1. By Using Auxilary Calendar Table Based on the weekdays of start date and end dates. **
SQL Server (T-SQL specifically) is not usually the best place to write a function for modifying the case of your data. String functions are generally slow and often a bit cumbersome to implement. That being said, it’s not uncommon to have data in your tables that needs to be “cleaned up a bit”. In situations like this, it is acceptable to write and use a function like this. With SQL, it is easy to convert strings to upper case or lower case, but what about making it mixed case/title case. This functionality is useful in many different situations. There are many examples on the internet that show how this can be done. Some work better than others, and perform better than others. The simplest versions of this will loop through a string, character by character, and capitalize anything following a space. Unfortunately, this is not always adequate.
For my usercontrols I tend to use the StructureMap BuildUp feature. I will leave it to [the big man himself][1] to [introduce you][2] to this feature. I use property injection in this case because the designer doesn’t like usercontrols that have constructors that are not empty, since it will try to execute the code in that constructor. So we revert to property injection and the BuildUp feature. I did say revert because I don’t think this is the best solution. But you have to be careful when using this.
I kinda like my VMWare Workstation 6.5 (soon to be 7.0). I always have at least 3 VM’s running. But I seemed to have some intermittent network problems. I use Bridged networking because that’s what I need. Most of my VM’s have a static ip so no problems there. The problem usually happens after I force a close on a VM because sometimes they crash without asking me. And then a weird thing happens. The machine looses its outgoing connection. I can start the machine (albeit a bit slower than usual) and I can ping the machine. I can see the network connection is alive and well and I can ping my host machine. But nothing beyond that. The first couple of times this happened I googled and googled and tried a myriad of things to fix it but I never found a solution. The only solution was to reinstall the VM or use the backup. Not a very fun thing to do.
I do not know if there is already code for table sizes (as used in SQL Server 2008 reports) but what I’ve seen on the net people are using cursors and temporary tables (completely unnecessary). NOTE (added later): In order to update table sizes in sys.dm_db_partition_stats you can execute next DBCC (all tables for current database): DBCC UPDATEUSAGE (0) WITH NO_INFOMSGS, COUNT_ROWS ;WITH SpaceUsage AS ( SELECT s.Name + '.' + o.Name as tblName, case when i.index_id < 2 Then row_count else 0 end as nRows, reserved_page_count as Reserved, used_page_count as Used, case when i.index_id < 2 Then (in_row_used_page_count - in_row_data_page_count) else p.used_page_count end as indUsed FROM sys.dm_db_partition_stats p INNER JOIN sys.objects o ON o.object_id = p.object_id INNER JOIN sys.schemas s ON s.schema_id = o.schema_id LEFT OUTER JOIN sys.indexes i on i.object_id = p.object_id and i.index_id = p.index_id WHERE o.type = 'U' and o.is_ms_shipped = 0 ) Select tblName as [Table Name], sum(nRows) as [#Records], sum(Reserved) * 8 as [Reserved(KB)], sum(Used-indUsed) * 8 as [Data(KB)], sum(indUsed) * 8 as [Indexes(KB)], sum(Reserved-used) * 8 as [Unused(KB)] from SpaceUsage Group By tblName Order By [Reserved(KB)] Desc Here is a version with more details.
Concepts in Mirroring I wanted to start writing a series of blogs on mirroring to share what I’ve learned over the years since SQL Server 2005 gave us the ability to setup mirroring for High Availabtility (HA). Before we go into that I want to go over the operating modes that we have in mirroring. We truly have two configurations for mirroring, Asynchronous and Synchronous. These are better known as operating modes High Availability, High Performance and High Protection. In my personal daily methods as a DBA, I think we can focus on there essentially being two modes of operation, High Availability and High Performance. High Protection is a sound method of mirroring but typically a setup that does not need to be done. This simply says we are taking a witness out of the picture in mirroring which forces a manual failover in the event of a lose connection to a principal database. In most cases this is due to the thought process that a witness must be a fully licensed and “hard core” database server much like the principal and mirror instances. In truth, we can use any edition including SQL Express for a witness so removing the witness in sychronous mirroring isn’t very ideal given the addition of transaction latency from this mode. The first major key to go over in Asynchronous mirroring is that this type of mirroring is only available in Enterprise Edition (and Developer). Some misconceptions are that if we remove the witness from the mirroring landscape on Standard Edition, we achieve asynchronous mirroring. This is, however, not true. In this case we are running in Synchronous mode but without automatic failover or safety off. Transactions are still synchronized on both partners first even without the witness. So in short, we still have the added performance hit with synchronous mirroring but without automated failover abilities. To achieve true asynchronous mirroring we need Enterprise and the features it brings along with it.
Yes, I still use svn and yes perhaps I should try that Git thing people keep talking about. But anyway. Since this post is for my pleasure and my pleasure only I will post a little something to remind me how to solve those tree conflicts. Because I keep forgetting how to do it. First of all I get a message on commit saying there is a tree conflict. Than we do an update and forget to take a printscreen.