Monday, July 25, 2011

VS 2010 Database Projects Post Deployment Scripts not Executing

Today I have been dealing with a really frustrating problem when working the DB Projects in Visual Studio 2010.

One really great feature is the pre/post-deployment scripts that you can execute on each deploy for things like static or reference data.  Or in some cases some test data as well not run by a data generation plan.

My issue was whenever I'd click deploy, the DB would be recreated, my tables I updated were created as expected, but it would not execute the post deployment file.  After some help from a co-worker, he diagnosed and found the problem was with the Build Action property on the file itself.



To correct, select the Script.PostDeployment.sql file in the Solution Explorer.  Click F4 if necessary to display the property grid.  Click Build Action, choose PostDeploy.  Deploy away.

Hope this saves you a few frustrating hours.

One note, you may only have 1 post deployment file in your project, use SQLCMD :r syntax to run all the scripts you want to execute post deploy.

Sunday, March 27, 2011

The greatest ViewState attribute to ever exist - Dynamic Controls just became easy

Recently at work, we were dealing with the ol' dynamic controls and ViewState problem. You know.. This one.

Failed to load viewstate.
The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.

I've seen a lot of *elegant* solutions on how to solve this. All these examples proving it out what have you.

I can't beleive Microsoft would hose us over with such a thing!!!

Well, they didn't... Hello ViewStateModeById !

How does it work?  Reflect it, what you'll find is that it simply iterates through the control tree by name instead of the index version which iterates through the tree (for each INamingContainer ) and then takes a value at the same index position in the ViewState statebag.  This is highly efficient, and with the way web forms are typically used, it works.

The counter to the ViewStateByModeId is performance.  But look at most of the dynamic control ViewState problem solving methods out there.  You'll find a great many simply use the same method to find the name of the control in the control tree.  If you consider the general computing power of modern servers, the performance impact is negligible.  There are edge cases where you have massive control trees, but if so, it might be a good idea to look at your overall page structure and other optimizations.  Don't blame it on the ViewState.

Not only that, they implemented it as both a property on Control and an Attribute.  Remember that Page is inherited from Control, so OnInit, just set the property first, then add your controls here not in Page_Load.  The lifecycle has already passed the LoadViewState event. 

There is one gotcha.  It does not quite work correctly on radio groups, so you have to request the value from the Form in order to set it, get values.  

One line of code that has saved me more hours and that much frustration than is fathomable.  Hope you get the same. Time to cross post the hell out of this.

You're welcome ;)

Sunday, December 26, 2010

Some great jQuery UI Links

50 useful links.  Was browsing for a combo box that was prettier than the current. 

http://www.noupe.com/jquery/50-amazing-jquery-examples-part1.html

Saturday, December 11, 2010

jQuery UI Tabs + XSLT + Double Page_Load Event + and carriage return

You know, one of the great things about having ADHD is I now have an excuse for getting side tracked and going on a code jungle adventure to solve bugs of epic proportions.

And that's just what happened this weekend!

I've been using jQuery a lot more right along with ASP.NET MVC 2.  As most, I keep working on old projects and simply bring them up to speed, try different things out, the like.

For those new to jQuery, it is a high performance, micro footprint, JavaScript library that that makes it possible to make client side development as extreme as something like Facebook for developers even like me... Not only that, there are literally thousands of extensions for this thing.  The one I was playing with is known as jQuery UI Tabs

I chose to use an XML/XSL content engine I had written to do some email templating.  I wanted to convert this to a dynamic form that would be driven by XML. Basically, I wanted to create the input form + output(s) from common schema and neither knows of the other or has dependency.  Which is pretty much what XML is there for... ;)

One such feature was to be able to break the input into a friendly / easy to use Form.  Using an XSL transform, It rendered an HTML form of 1..x # of tabs. Without the details of how the whole tab system works, for each tab, you have a
with a unique identifier such as tabs-#.  Where # is a sequential value from 1..x.  Using the syntax

 $("#tabs").tabs();

The XSL that transform to XSL looks like so:

<xsl:template match="tab">
    <xsl:variable name="tabNumber">
      <xsl:number value="position()" format="1" />
    xsl:variable>
 
    <div>
      <xsl:attribute name="id">
          tr_<xsl:value-of select="$tabNumber" />
      xsl:attribute>


Clearly looks clean. Code generates, tabs generate...

but then... something weird happens..  The tabs show up a second time, but this time, no formatting, everything looks horrible on the screen, and the Page_Load is called again by a GET.  Combine this with the dynamic nature of the control, and it becomes incredibly hard to debug.

I disabled all my jQuery/JavaScript I had written.  Still getting a double load.  Not only that, injecting it.  I disabled the tabs portion itself, still coming up twice.  I'm getting a JavaScript runtime error much like when ASP.NET Ajax has two versions (1.0.xxx & 3.5) in the same application.  Checked that... Fine.

Maybe jQuery has a bug in this version (I had downloaded 1.4.2 a few months back), so I upgraded to 1.4.4.  I switched to the Google CDN.  Over and over it kept coming back like a g*d damn zombie!

I go back to my XSL, did I have a script reference in there?  Nothing stands out.

Finally, trusty ol 'View HTML' and your favorite text editor.  Combing line by line, I'm trying to figure it out.  It's not standing out.  Until I finally come to the

<div id="tr_tabs-2">

or that's what I thought it should have looked like........

Not quite though sport!  Looked a little more like

<div id="&#xA;          tr_tabs-2">

Well, that certainly won't be found by tabs, and looks like we might have a little bug if so.  I don't know, I wasn't going to full investigate it.  I wanted to fix this and be done.  Why would this happen?  Back to XSL

Ends up, Visual Studio and some editors like to put extra spaces and XSL doesn't like concating + string trimming without using XSL functions. 

Remember this nugget?


<div>
      <xsl:attribute name="id">
          tr_<xsl:value-of select="concat('tabs-', $tabNumber)" />
      xsl:attribute>


That little tr_ constant throws the whole thing off.  If you change it to (you will also notice the added spacing in Visual Studio when pressing delete)   It works.


<xsl:attribute name="id">tr_<xsl:value-of select="$tabNumber" />xsl:attribute>

However, knowing how I like to hit Format Document, and this seemed like an easy mistake to make, I couldn't imagine this was the best way.  Nope!  of course not.  Using the XSL function (concat) solved this easily and still can use my format document feature in VS!  

<div>
      <xsl:attribute name="id">
        <xsl:value-of select="concat('tr_tabs-', $tabNumber)" />
      xsl:attribute>


No more double GET and odd behavior.  I hope this helps someone!

Monday, August 2, 2010

Version issues between TFS 2008 and TFS 2010 Libraries

Finally been able to work on YakShaver a bit more trying to finally finish up what I'm calling the SFD feature.  As I've been working on it off and on for the past few years there sometimes can be days (read weeks/months) between getting dedicated time.

Recently I made a change to go from the TFS 2010 libraries back to the 2008.  Not because something was wrong with them, just that one of the installation locations I had would not allow me to install TFS 2010 (anything related).  So, I rolled back my project to the 2008 and apparently just left it as is (never compiled or compiled and didn't pay attention to errors).

Fast forward to last Friday.  I've finally got time, open up the solution, notice I have some errors.  "Not a big deal" I think to myself, how much could be wrong?  I knew it already worked before.  But I could not get this to compile.  The errors were all pretty close to the same.

Microsoft.TeamFoundation.Build.Client.IProjectFile' is obsolete: 'This interface has been deprecated. Please remove all references.

Not just this interface, IBuildStore was another.  But this was only a warning, so I ensured I had TreatWarningsAsErrors turned off, still couldn't get it to compile.  WTF, was all I could think.

As I started diagnosing, I looked at another library I had referenced (not a project file reference, but just a DLL I had written previously.)  This DLL referenced the 2010 libraries and upon compilation would cause the error.

I didn't see how this could actually cause an issue, but wanted to verify.  I found the project file for the DLL in question, included it in my solution, and sure enough same error.  I modified the project to utilize the 2008 libraries (9.0.0.0) instead.  Compiled.  Poof. 

It was logged as a bug with TFS in connect.  But doesn't look like it is.  Here is the original link to see more details. 

https://connect.microsoft.com/VisualStudio/feedback/details/577048/cannot-implement-ibuilddefinition-class?wa=wsignin1.0#tabs

Hope this helps, I struggled for a couple hours on it and the error message doesn't lead you down this path.

Friday, June 18, 2010

New development laptop

After 2.5 years, my current development laptop is just not keeping up as I would like.  The new rave seems to be in the i7 series processor from intel and the T7500 Core 2 Duo just does not handle VMWare + Visual Studio 2010 and a few other apps quite as well.  Plus, Quad Core vs. Duo.  Easy call. 

Like before, I wanted to make sure I got a laptop that lasted.  I consider 2.5 years (1.5 years after paying it off) to be a acceptable amount of time, especially for a laptop.  I upgraded it over time of course, but it does have it's limits. 

As a result, I ordered a new Dell Studio XPS 16.  The basic configuration from Dell is

Intel i7 720QM Quad Core
500G SATA HDD @ 7200 RPM
8 GB 1333MHZ
1920 x 1080P - Didn't spring for the RGB LED. 

Instead.  I ordered one of these caddy's.  and this SSD drive. 

The plan.  Replace the 500GB drive with the SSD -> install Windows 7 using slot load DVD


Replace Slot load DVD with caddy from above.  Put pre-existing 500GB drive, now I have a SSD + HDD XPS system.  Install Visual Studio Program Files on my SSD.  Store project on the HDD. 

If all goes well, this will be my fastest mobile PC to date.  All this for < 2000 and a good amount of lifetime in it.  Looking forward to getting it in, hopefully it lives up to all my expectations.