Truncate Logs for SQL Server 2005

I’m frequently trying to figure this out but never remembering the exact syntax, so here it is! A quick/easy way to truncate logs on a database via script!

* NOTE: I don’t recommend this for production databases unless you tweak it to be good. This is more for dev environments where you don’t really care about transaction logs!

USE [{DatabaseName}]
DBCC SHRINKFILE({TransactionLogLogicalName}, 1)
DBCC SHRINKFILE({TransactionLogLogicalName}, 1)

Happy truncations!


What is ALT.NET?

When we were discussing the Indy ALT.NET group’s goals with others, we were asked, “How are you going to distinguish Indy ALT.NET from the Indy .NET User Group?” This was a GREAT question!

In coming up with that answer, I’ve mulled around and tried to come up with a definition for ALT.NET. There are plenty of posts out there that have attempted to do this but the reality of the situation is that there is not yet a single, concrete, agreed-upon answer to this. So as such, I’ll add my thoughts to that cloud of what some people think ALT.NET is.

In trying to define this, I am going to outline the process I went through in coming up with this definition. I think going through the process helps you understand what it is just a little bit better. Here was my first attempt:

The concept of ALT.NET means that you try to use all tools and techniques available in an appropriate way to do your job in the best and most efficient way possible.

The problem with this definition is that it leaves you just as confused as you were before. From this definition you would believe that ALT.NET is the same as being a good software engineer. I believe this definition is a 100% accurate definition but unfortunately, it is 90% useless. So let’s try it again and fill in not just what ALT.NET means but also what it stresses.

The concept of ALT.NET means that you try to use all tools (whether mainstream in your specific industry or not) and techniques available (whether mainstream in your industry or not) in an appropriate way (without overkill) to do your job in the best (as defined in almost any possible way) and most efficient way possible.

With these stresses, this definition starts to make a little more sense, but it’s still not all that useful. Let’s try it again and this time add a lot more to it.

The concept of ALT.NET means that you try to use all tools and techniques available in an appropriate way to do your job in the best and most efficient way possible.

The tools may come from any source whether it’s your industry or not. For example, there may be some tools that Java developers take for granted that are just completely unknown about in the .NET industry. Or perhaps there is a tool used by accountants to ensure calculations are done correctly and that tool would be an awesome yet non-obvious solution for implementing a suite of unit tests for your code.

Like the tools, the techniques may also come from any source whether it’s your industry or not. Perhaps you’re running into some architectural problems of how to lay things out and a VLSI engineer has a technique for laying out blocks of functionally-related items on their boards that an architect could use in laying out their classes.

In addition to these examples, the concept of ALT.NET even takes it one step further. Not only should one look to other industries for a tool or technique, one should also consider developing new tools or techniques to as part of the greater evolution of things. While they’re not ALT.NET-created concepts, “alternative” methodologies such as Domain Driven Design (DDD), Behavior Driven Design (BDD), and Agile Development have not always been around but had to have been dreamed up at some point. I believe ALT.NET encourages the evolution of our industry by encouraging such new “outside the box” concepts to be considered.

Now, one thing to be careful about is overusing these tools and techniques. Just as an architect needs to ensure he/she does not over-architect the system, you must also ensure you do not go overboard with these tools and techniques. They need to be used appropriately and not just for the sake of using them. In fact, often times the KISS methodology applies! When determining what tool or technique to use, you need to ensure you make such a decision to ensure you create the “best” thing you can. Best is a very vague word here that can be defined MANY different ways and that’s for you to decide. Perhaps it means the quickest solution to code. Maybe it means the fastest solution to execute (from a performance perspective). Perhaps it means the cheapest third-party tool that fits the bill. Or maybe it means the easiest for a user to interact with. The “maybes it means” list can go on forever.

Whew! I think that just might be it! I think that just might be a pretty good explanation of what ALT.NET is!

Now, while I believe that is a good definition for it, I think it’s important to discuss one more thing that has been a popular topic of debate. Is ALT.NET divisive? I am going to change the question a little bit and not answer whether it is or not but rather it should be (to me the difference in the questions are due to the rude and perhaps elitist behavior of some individuals and not the fundamental concept of the ALT.NET movement).

So, should ALT.NET be divisive? My answer is a simple “no.”

Let’s go back to my very first definition of what ALT.NET is:

The concept of ALT.NET means that you try to use all tools and techniques available in an appropriate way to do your job in the best and most efficient way possible.

As I stated before, this definition essentially means that you are simply trying to be the best software engineer that you can be! Again, I believe this is a 100% accurate definition. And by this definition, there should be absolutely no division created within our industry because of ALT.NET. This is what all of our peers should be doing. ALT.NET focuses on some non-mainstream things and in some scenarios such things are the “best” way of doing things but there are certainly times when they’re not the “best” way of doing things. The only question that remains is what exacly that “best” word means to you. Let’s use some examples.

Consider that you’re a consultant working on a small application for a non-profit company where the code will later be maintained by college students on a somewhat casual basis. In this case would it make sense to invest in a potentially complex way of architecting the system so that it follows a generic, standard philosophy? Perhaps but probably not if it is going to be too complex for the college students to easily (and safely) maintain.

Now consider that you’re a software development shop that regularly works on custom projects for clients. In this scenario, your business model could be built around efficiently pumping out successful projects in a repeatable fashion. In this case would it make sense to invest in a potentially complex way of architecting the system so that it follows a generic, standard philosophy? Probably so once you have nailed such a thing down you can repeat it regularly to increase productivity in the future.

One more example. Consider that you’re the said software development shop above and you are working on a very critical project with a tight deadline and you have not yet mastered this new architecture. In this case would it make sense to invest in a potentially complex way of architecting the system so that it follows a generic, standard philosophy? I would say probably not. Any significant fundamental change to your current process can introduce some very significant risks. With that being said, many of the topics that ALT.NET covers can introduce significant risks if they’re used in inappropriate situations or are not done well (which can very well happen since they’re not very widely understood in the industry and not many people have much experience with a lot of these things). So you must consider that doing such a thing can be a big risk.

In the last example, I hit on one very big thing and that is that many of the ALT.NET-focused topics bring a lot of risk with them because they are not yet really all that proven to be successful. There are many companies and situations where this is unacceptable and in those cases, the mainstream tools and techniques should probably be considered. This is not to say that the ALT.NET-focused topics are “too difficult” for certain people. It has nothing to do with that at all! It has everything to do with that “best” word. But I think people who determine that the ALT.NET topics aren’t currently “best” for them may still want to consider following the ALT.NET topics for their personal professional development. Increasing your awareness of various things is a good thing, afterall!

Now I want to end this post with a last closing thought. Personally to me, my interest in this ALT.NET movement has two motivations to it:

  1. I want to learn about some of these neat new things that I’ve never heard about before!
  2. I want our Indianapolis development community as a whole to learn about some of these neat new things too!


EDIT: 4/30/2008 4:13pm EST
I have been asked for some links on various community sites by some people who are just now being introduced to the ALT.NET movement. Here are a few links to get you started. Over the next day or two I’ll see if I can get a “History of ALT.NET” post up. 🙂

David Laribee’s coining the term ALT.NET
MSDN Magazine article on ALT.NET
ASP.NET Podcast Show #103 – ALT.NET with David Laribee

Indy Code Camp was fun!

Indy Code Camp is in its last session now. It was quite fun!

Personally, I really wish Indianapolis would have more events like this! This city is really starved for community software development events, at least applicable to .NET developers. Despite the slumping economy world-wide, the market in Indy is really good for .NET developers, which means we’ve been having a lot of new people moving into the area. The community here is growing quite fast, but we still don’t have many events. Currently we have the monthly .NET User Group meeting, a yearly Indy Tech Fest, and then random events similar to this. I know there is also Microsoft’s DevCares, I believe Crowe Chizek sponsors something, and there will soon be some Indy ALT.NET presentations. We really need more events to satisfy our hunger and the growing number of people in town, though!

But back to topic, I enjoyed Indy Code Camp! We had some really good presenters!


Speed up .NET Compact Framework compile time by a LOT!

I was complaining on Twitter about the long time it takes to compile a Compact Framework application and Steve Schoon informed me of a hack you can do to DRASTICALLY speed up the time it takes to compile! You can get the details here.

Read the entire thing so you are aware of what you’re disabling by performing this hack but unless you are constantly flipping back and forth to various different target platforms with your mobile development, you shouldn’t need this feature very often at all! It dropped our compile times down from about 3 minutes to about 10 seconds. It was amazing!


IndyALT.NET Site is live!

IndyALT.NET is now live!

Right now it’s being hosted in somebody’s house (thx to Paul Hacker, MSMVP, for sharing his servers temporarily!) We’re excited about our first two events! Next month we’re having Mike Griffin come in for some training on the EntitySpaces OR Mapper. In July we are planning on having Todd Anglin come in and show us some good stuff with some of Telerik’s products. And who knows what else we’re going to do!

Interesting and busy times to come!


Exclusive access for Database Restores on SQL Server 2005

How many times have you tried to run a database restore on SQL Server 2005 only for it to fail because you don’t have exclusive access to the database (for whatever reason from SSMS being open to anything else)? Happens to me quite frequently. Here’s a handy piece of code to help prevent that:

-- Your restore script here.

What this does is sets the database into single-user mode (which effectively kills all other connections to it), restores the database, then when it’s done it sets it back to multi-user mode. I LOVE using this for restores that I seem to do over and over. 🙂

DataAdapters and ReadXML / WriteXML

I am working on a project that contains nearly identical clients (same basic featuresets, different UI) in very different environments (Winforms, Mobile, and Web). The biggest difference is that the web sites (one client-equiv site, one admin site, and a set of web services) contains some additional functionality. I’ve architected this to maximize the amount of code we can reuse in all of these environments. The data tiers all implement common interfaces or abstract classes. The business tiers all extend classes in a shared DLL. And the presentation tiers are all independent but all go through the same basic API to call into the business tier. If I get interest in it, I can go more into this.

Because there is so much common functionality, the databases are all very similar (and in some cases, large parts are 100% identical). The winforms and web systems all use SQL Server for their databases (Express on the clients but we don’t hit any of those limitations). However, with our Compact Framework project, it’s quite a bit different since we have to use SQL Server Compact Edition (or whatever they’re calling it this month). We have yet to find an easy automated way to take a desktop database and convert it into a compact edition database, so we wrote a little utility. It only took a couple of days, so it wasn’t that bad. We essentially call the sp_tables proc in SQL Server in our development database, iterate through the results, and generate CREATE TABLE scripts based on it. Easy enough. And for the data, we simply use Command Builders and DataAdapters (we use a SqlCeCommandBuilders and SqlCeDataAdapter for the Compact Edition interface but it works just fine for us) and the WriteXml and ReadXml methods that go with it.

During development of our utility, we used the IgnoreSchema option with WriteXml when trying to fix a bug and forgot to turn it back off. This just came back to bite us in the ass! One of our tables in the final database that we’re converting is called “MessageType” and is a simple lookup table (2 ints and a varchar(50) is all). Well, when we were trying to import the data for it, we were getting an exception on the DataAdapter.Update call: “There was an error parsing the query.” We spent 2-3 hours trying to figure it out and we finally figured out the problem and it came back to that IgnoreSchema option that we had set and erroneously left!

So we have our “MessageType” table and we also had an “AuditLog” table. A column in the AuditLog table was called “MessageType” and was completely unrelated to our MessageType table. Yeah, bad naming here – we need to fix that obviously but it shouldn’t be enough to confuse .NET, right? Wrong! Since our XML files were generated without schemas, .NET must make some assumptions about the XML coming in. In this case, I think it decides that any XML node that comes up as <MessageType> is an entry for our MessageType table, when it comes time to populate our MessageType table. But when it goes into the XML we pass it, it sees the <MessageType> nodes from our AuditLog table and because the tag matches, it tries to start parsing it as though it belongs to our MessageType table, which will obviously fail! So now you see the source of our problem.

Switching IgnoreSchema back to WriteSchema was a simple fix to the problem. Other things can be done that could have resolved this specific problem but this was the most wrong thing we had done and needed to fix. Now, time to go play with a freshly generated set of SQL Server Compact Edition databases on our PDAs! 🙂


Automatic Generation of API Documentation for .NET 2.0 Code

I was recently given the task to generate some API documentation for all of the code on a project I was working on (11 different projects, 3 different solutions) so I began looking into what was available. I remember using NDoc with old 1.1 projects, but that project was apparently abandanded. Microsoft has an October 2007 CTP release for a replacement called Sandcastle. It’s a suite of files that provide the core functionality of generating HTML and CHM files for documentation in an MSDN-like style. Apparently, this is what Microsoft uses internally to generate their MSDN documentation.

Unfortunately, Sandcastle comes with no GUI to use it but fortunately, there are several free GUIs written out there to do it for you. To find out more about it, I thought this site was most helpful.


VS2005 Deployment Projects install new version with old version’s custom action assemblies

I’m working on a project where we use Deployment Projects to deploy our public application. We’re still in beta phase so we don’t have a huge number of releases under our belt yet but so far things have been going pretty well (well, at least since we’ve gotten past the initial hurdles in getting our first installer out). Well, something new has jumped up and surprised us. And honestly, now that I understand it, I’m shocked that we’ve not seen it in any of our last 5ish releases.

So here’s the context: We had a prior version of our app installed and we wanted to upgrade from that version to the newest version. We have the installer uninstall the old version (for this part hopefully by now you know that it’s good and important for all assemblies in the installer to be properly versioned and at or above 1.0). This is done by the freebie stuff and the Uninstall events that get fired within our Installer Class/custom action to manage a few things, including our databases. Next the new version gets installed (again by the freebie stuff and custom actions). The last thing our custom action class does is upgrades our databases from the older verson to the newer version. This is how we’ve done things for the past 5ish versions and everything has worked just fine and dandy as long as we’re on the ball with versioning our assemblies correctly.

Well, this version I updated all of our installer files just as I had done with the previous versions and when I went to test it, I was surprised. For some reason the install seemed to work fine EXCEPT for our custom actions. To make a long story short, what was happening was that our custom actions from our previous version were getting executed when the installer was installing the newer version!! So obviously since our databases are maintained by these custom actions, the problems were pretty obvious from the beginning.

I ultimately found this article online which points to this KB article of Microsoft’s (EDIT: this is the VS2005 version of the bug, I previously linked the VS2003 version of the bug) and it turns out that this is a bug in Visual Studio 2005 that was posted in August of 2004. The short version of the problem is with the assembly name for our custom action. When Windows Installer loads CustomAction v3 for the uninstall and attempts to load CustomAction v4 for the new install, it unreliably does not load v4 because it sees it already has CustomAction loaded but forgets to care about what version it is. So then when the new version of the app fires the events for our DLL, they get handled by the old code and not by the new code.

There are two things to be aware of with this scenario to fix it. The first is an end-user work-around in case you need such a thing for an installation that you might have already made public. If the end-user runs your installer and this happens, running the installer again and selecting “Repair” will then run the correct version of the DLLs. Now this may or may not help you, depending on your scenario. Luckily for us, this is an acceptable work-around without trashing any data because of our architecture around updating our client databases with each release. Now the second thing to be aware of is a more permanent fix. If you change the Assembly name for your custom action to be unique with each deployment, this will allow you to prevent this from happening again. So instead of my custom action’s assembly name being “Company.Project.Installer.CustomAction” it is now “Company.Project.Installer.CustomAction_v1.0.0.3” and of course I change this with each release.

Good luck and I hope you find this problem and solution before wasting hours of time like I did!

Debugging Visual Studio 2005 ASP.NET apps on Vista Home Premium

If you have an ASP.NET app hosted by IIS7 on any Vista Home edition (though I’ve only used Home Premium), it fails because Vista Home Premium lacks Windows Authentication. Fortunately, Microsoft is aware of this and has issued a fix. Unfortunately, it’s not part of Windows Updates so you’ll have to go get it yourself.

You can find KB937523 here describing the situation:;EN-US;937523

The fix can be found here:

« Previous PageNext Page »

Jaxidian Update is proudly powered by WordPress and themed by Mukkamu