Posted on August 27, 2008 17:34 by baugustine
 

Interesting issue Shawn and I ran into today with the <script> tag in ASP .Net. A page was defined with <script> tag that was closed with a /> instead of </script> as shown below.

 

<script language="javascript" src="myJavaScripts.js" type="text/javascript" />

 

And any time a control on the page did a post back it started throwing java script errors such as "Object Expected". Other variants could be "__doPostback not defined" but I did not see that error. Anyway the culprit was the /> closing tag. So to fix the error I had to end the <script> tag with </script> tag instead of />. So changing the above statement to

 

<script language="javascript" src="myJavaScripts.js" type="text/javascript"><script>

 

fixed the error.

 

Incidentally this worked also.

 

<script language="javascript" src="myJavaScripts.js" type="text/javascript" />

<script></script>

 

Go figure.



Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted on August 17, 2008 13:35 by baugustine
 

Team Foundation Server (TFS) has a great feature called shelving. It allows you store a copy of your source code changes on the TFS server. Please note that this is different from checking in the code, because the copy is set aside temporarily or shelved under your userid. Since the code is not checked in you can be confident it is not going to break your team's nightly or continuous build.

 

There are several ways to shelve your changes. The easiest way to do it is from Visual Studio, click on your Pending Changes window, and select the files and click Shelf button. In the dialog window that opens up enter a Shelveset Name and click Shelve. If you give a Shelveset Name that is already existing it will ask for confirmation to overwrite it.

 

For unshelving, open Pending changes window in Visual Studio and click Unshelve. By default it will show you all the shelvesets for your userid. Click on the self set name from the list and click Unshelve. It will bring down your shelved code files to your local workspace automatically check it out from the TFS server.

 

For more ways including command line to do shelving and unshelving look at the MSDN documentation here.

 

Some of the uses of Shelf feature are:

  • Set aside temporarily a feature or some code change that you are working, because you are now assigned a different task or a bug to fix.
  • Collaboration on a code change. Say you are working on a code change and you need some extra information from another team member to finish it. You can shelf your code and have your team member unshelf it and provide the extra information and check it in.
  • Use it for code review purposes before checking it in for build.
  • Use it as a personal code change backup. I normally give a shelfset name of bkp (because I am lazy), and allow the confirmation dialog to overwrite my existing backup. You still have to remember to manually do this though. I have made it a practice to do this before I leave for the day. May be I will automate this some day and blog about it.

For more information about shelving and unshelving look at MSDN documentation here. There is also a 10 min video here that gives you a hands on approach.



Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted on July 26, 2008 11:47 by baugustine

Most of us application developers have worked with SQL Server databases and especially tables with IDENTITY property. We have all written stored procedures to insert records into tables with columns that have IDENTITY property set.

In case you are not familiar with IDENTITY property, this property can be set on a column that has a data type of decimal, int, numeric, smallint, bigint, or tinyint. When this property is set SQL Server automatically populates that column with a next higher number in the sequence when a record is inserted. So it has been somewhat of a common practice for application developers to set the IDENTITY property for an Id column of a table and let SQL Server manage the unique primary key values. More information about IDENTITY property can be found here

Normally one of the requirement when you write a stored procedure to insert a record into a table with IDENTITY column is that you will have to pass the Id value of the newly created record back to the application. Lot of developers use the @@identity variable in SQL Server to do that. And most of the time this will work because the @@identity variable holds the last identity value generated by the insert statement. Run the sql1.sql file from the attached zip file to see this working.

So far so good. Now all that is needed for this nicely working proc to fail to return the correct Id value is to add a trigger to our table, and that trigger inserts a record into another table (say an auditing table) which also happens to have a column that has its IDENTITY property set. Run the sql2.sql file from the attached zip file to see this behavior.

So why did the incorrect id values are returned after adding the trigger. The reason is that @@identity does not have a concept of scope. It always returns the identity value of last inserted record in the database. In this case it happens to the audit table record that got inserted last. So to overcome this behavior we need to modify the proc to use the scope_identity() function to return the last identity value instead of the @@identity variable. Run the sql3.sql file from the attached zip file to see the modified proc and the correct behavior.

So always use @scope_identity() function in your insert proc to return identity column values even though you may not have triggers on your table during development. Because adding a trigger on your table is beyond your control. All it takes is for your proc and application to not work properly or even worse cause data corruption is for someone else to add a trigger on one of your tables for some reason or the other.

ScopeIdentity.zip (1.70 kb)



Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5