Epic Blog of Awesome

code.tech.sci.math.art.write

Visual Studio 2010 Find in Files

It’s always bugged me that with the ctrl-F dialogue in VS2010, there’s no way to specify common find options like excluding certain filetypes, searching on a list of filetypes and others. Well, there is a way. Get ready for it.

CTRL-Shift-F

Brings up a better find dialogue which includes find and result options.

Install ASP.NET 4.0 / Silverlight 4 w/ SQL Merge Replication

There were some challenges in this 4-hour install that I wanted to get down while it was still fresh in my mind.

Database for the application is SQL 2008 R2 is distributed among three servers, one in the States, one in Asia and one in Europe. Merge Replication is used to synchronize the databases.

There were two DB schema changes required for the application upgrade. Merge replication handles some schema changes automatically without disruption to publisher or subscriber servers. One of my schema changes was a length change to a varchar column and I was able to do that on the publisher without a problem. Merge replication handled pushing the change to my subscribers.

The other schema change, however, was adding an identity property to a column, which requires dropping and re-adding the table. This can’t be done while the table is an active article in the replication setup. These are the steps I took to make that change:

  1. Remove the table from the publication articles.
  2. Create a new subscription snapshot
  3. Drop tables on subscriber databases
  4. Make schema changes on the table on the publisher database
  5. Add table back into the publisher articles
  6. Create a new subscription snapshot
  7. Use the replication monitor to ensure synchronization is successful.

The web application was compiled in Visual Studio and Published to a local directory. Remoted to each web server and deleted application all application except for Web.config. Mapped to local box, pulled in the published files.

The web site wouldn’t load. It was giving me 401 errors, which of course actually had nothing to do authentication problems. The web app did come up  on the two other web servers, so after some comparing and troubleshooting I fixed the IIS configuration on the server. It turned out that the application pool was possessed. Seriously, this was strange. As long as the web application was assigned to this application pool, I’d get 401s. When I changed the application pool to a different one of the same type (ASP.NET 4.0 Classic Mode), the app worked fine. Change it back, 401s. Change it back, works.

There were a couple of other details. Forgot to add a couple new rows of data to a configuration table. But no other big problems.

Duplex Service in Silverlight

Silverlight offers us many choices to work with services to get data into our applications. Supported technologies include WCF, ASMX, REST, WCF RIA Services etc. Through the use of any of these, it’s quite easy to get data from the server to the client application and vice versa. They all have one thing in common: before the data is sent, the client has to perform a request to the server to do so. The communication is known to be client-initiated. But what if the server wants to initiate communication by sending some data to the client, without there being a request first? In this case, we need to use duplex communication, so that both sides of the communication channel can start sending data.

via The duplex story: looking at duplex communication in Silverlight (Part 1).

Exception handling and nested transactions

I wanted to use a template for writing procedures that behave as intuitively as possible in regard to nested transactions. My goals were:
The procedure template should wrap all the work done in the procedure in a transaction.
The procedures should be able to call each other and the calee should nest its transaction inside the outer caller transaction.
The procedure should only rollback its own work in case of exception, if possible.
The caller should be able to resume and continue even if the calee rolled back its work.
My solution is to use a either a transactions or a savepoint, depending on the value of @@TRANCOUNT at procedure start. The procedures start a new transaction if no transaction is pending. Otherwise they simply create a savepoint. On exit the procedure commits the transaction they started (if they started one), otherwise they simply exit. On exception, if the transaction is not doomed, the procedure either rolls back (if it started the transaction), or rolls back to the savepoint it created (if calee already provided a transaction).
Because of the use of savepoints this template does not work in all situations, since there are cases like distributed transactions, that cannot be mixed with savepoints. But for the average run of the mill procedures, this template has saved me very well.

via Exception handling and nested transactions.

Good post about SQL Nested transactions and Rollback

You *cannot* nest transactions.
The only thing that happens if you nest several BEGIN TRAN is that no
warning message is given (to keep logs and such clean) and the fact
that @@TRANCOUNT increments by 1, nothing else. You have *not* started
another transaction.

You can *only* commit when @@TRANCOUNT = 1
If you say commit and @@TRANCOUNT > 1, all that is happening is that
@@TRANCOUNT decrements by 1. So, not until you reach 1 will any work
be ‘truly’ committed to the base.

ROLLBACK will do two things that’s important to be aware of…
1) It will rollback all work back to the *first* or *outermost* BEGIN TRAN
2) It will also *reset* @@TRANCOUNT to zero (no matter the previos value)

So, ‘normally’, it may look something like this, question is what will
happen…?

BEGIN TRAN
– do some stuff
INSERT myTab SELECT 1
BEGIN TRAN
– do some more stuff
INSERT myTab SELECT 2
– do a commit
COMMIT
BEGIN TRAN
– ..even more stuff
INSERT myTab SELECT 3
– funky stuff happens
ROLLBACK

Now… as we say ROLLBACK here.. what will happen? =;o)

myTab now contains..
1?
1 and 2?
1 and 2 and 3?
Just 3?
Nothing?

…and do we have an open transaction hanging around.. or not?
Try figuring the answer before testing ‘for real’, and try to get the
understanding for why you think what happens and why. This is very
simplified, and just a pointer at the basics of transaction handling -
it’s by no means worthless knowledge, though…

via Using BEGIN TRAN…COMMIT TRAN.