Tuesday, July 25, 2006

Intellisense for SQL Server



SQL Prompt™

Intellisense for SQL Server, plus other features

* Code completion for fast, accurate script building
* Discoverability in SQL Server query creation
* Keyword formatting, code snippet integration other extended features
* FREE until 1st September 2006
* No time-bombs, no restrictions

Red Gate SQL Prompt is free until 1st September 2006

SQL Prompt provides Intellisense® style auto-completion for Microsoft SQL Server editors. It will tell you the exact formatting you should use for your SQL commands, while you are writing them and will therefore help you write fast, perfectly formatted SQL statements. SQL Prompt improves the productivity of all SQL script creation. SQL Prompt can be downloaded free until 1st September 2006 and we are providing forum support on the SQL Prompt support forum.

SQL Prompt simply sits behind the scenes and provides unobtrusive help when you press Ctrl-Space or when you type "." after a table/view/alias name.

Features include :

* Table/View name completion
* Column name completion
* Stored procedure name completion
* USE completion
* JOIN/JOIN ON completion
* Auto-uppercasing of keywords
* Auto-popup after keywords

SQL Prompt works with Microsoft Query Analyzer, SQL Server 2005 Management Studio, Visual Studio 2005, Visual Studio .NET 2003, SQL Server 2000 Enterprise Manager, UltraEdit32. Please note that Intellisense is a registered trademark of the Microsoft Corporation, we have a dedicated web page describing Red Gate's relationship with Microsoft.

SQL Prompt

Visual Studio .Net Tips and Tricks - Book for FREE



Download this book FREE (PDF)
Visual Studio .NET Tips and Tricks explains how to use VS.NET efficiently. Organized into short and easy-to-grasp sections, and containing tips and tricks on everything from editing and compiling to debugging and navigating within the VS.NET IDE, this book is a must-read for all .NET developers, regardless of expertise and whether they program in C#, VB.NET, or any other .NET language. This book covers the Visual Studio .NET 2002, 2003, and 2005 Beta 1 releases.

In this book you'll find the following:

More than 120 tips for editing and writing your code, navigating within the IDE, and compiling, debugging, and deploying your application
Section dedicated to VS.NET 2005
Keyboard shortcuts for the majority of tips
More than 90 figures and screenshots

http://www.infoq.com/minibooks/vsnettt

Monday, July 24, 2006

FreeTextBox - best HTML editor for ASP.NET


FreeTextBox is the most-used HTML editor for ASP.NET. It is compatible with IE on the PC, and Mozilla and Firefox on all platforms. It is used in major Open Source projects such as Community Server and DotNetNuke as well as excellent packages like Smarter Mail.

Concurrency in SQL Server - Optimistic Concurrency Database Updating - Pessimistic Concurrency

The Problem

Most ASP.NET applications incorporate a database as a repository for data. At some point in the life of your application, a user of that application will need to modify a record in that database. As soon as the person selects a record from the database to be modified, the data selected is old and suspect. It is old and suspect, because the acquired data is now disconnected from the database and no longer accurately represents the original data in the database. The original database record may have been modified before the user is able to modify and save his/her changes.
So now we have the age old problem, how confident do we feel as developers that the selected data by one user will not be changed by another user before he/she has a chance to modify and save it back to the database? If we decide poorly, one user ends up overwriting another user's changes or causing excessive delays in the performance of a multi-user ASP.NET application due to record locking.

Pessimistic and Optimistic Concurrency

In a multiuser environment, there are two models for updating data in a database: optimistic concurrency and pessimistic concurrency.

Pessismistic concurrency involves locking the data at the database when you read it. You essentially lock the database record and don't allow anyone to touch it until you are done modifying and saving it back to the database. Here you have 100% assurance that nobody will modify the record while you have it checked out. Another person will have to wait until you have made your changes.

Optimistic concurrency means you read the database record, but don't lock it. Anyone can read and modify the record at anytime and you will take your chances that the record is not modified by someone else before you have a chance to modify and save it. As a developer, the burden is on you to check for changes in the original data ( collisions ) and act accordingly based on any errors that may occur during the update.

Depending on the application and the number of users, pessimistic concurrency can cause delays in your application. Other users may have to wait while another user has locked a database record. Worst case, you get an actual dead lock, because there is a cyclical dependency on database resources and nobody can complete his/her intended task. A timeout occurs in the application and nobody is happy, including the guy responsible for cutting you a check.
With optimistic concurrency, the application has to check for changes to the original record to avoid overwriting changes. There is no guarantee that the original record has not been changed, because no lock has been placed on that data at its source - the database. Hence, there is the real possibility of losing changes made by another person.

Simplest Thing Possible, But No Simpler

The key is to know your application and to pick a solution that best meets its needs.
If your application is a portal for your INETA .NET Developer Group Website, I dare say that there is absolutely no chance that two people will be updating content at any time. ;) You are lucky if you get one person to update the website. Hence, I would say this is very much a single-user environment and the heck with concurrency issues - they won't happen. The chance of overwriting someone else's data is slim to none as well as has very little repercussions if it happens.
If your application is a banking application and the repercussions of overwriting data is severe, concurrency issues will be a big concern and need to be judged accordingly. Although the chance of 2 users / processes modifying the same data may be slim to none in the application, the risk of it happening once may be important enough to use pessimistic concurrency and the heck with performance on the off chance that two processes may want to access the same data.

Optimistic Concurrency Strategies

If you are in a performance state-of-mind, chances are you will go with optimistic concurrency. Optimistic concurrency frees up database resources as quickly as possible so that other users and processes can act upon that data as soon as possible.
To the best of my knowledge, there are four popular strategies to dealing with optimistic concurrency:


1. Do Nothing.
2. Check for changes to all fields during update.
3. Check for changes to modified fields during update.
4. Check for changes to timestamp ( rowversion ) during update.


All of these strategies have to deal with the shaping of the Update T-SQL Command sent to the database during the updating of the data. The examples below are not very detailed on purpose and assume a basic understanding of ADO.NET. Below shows the strategies from a view point of 30,000 ft high.

Optimistic Concurrency on Update Strategy #1 - Do Nothing

The simplest strategy for dealing with concurrency issues during the updating of data is to do nothing.
The update command will not check for any changes in the data, only specify the primary key of the record to be changed. If someone else changed the data, those changes will more than likely be overwritten:

Update Product
Set Name = @Name
Where ID = @ID


One would hope that this means either 1) the application is a single-user application, or 2) the chance of multi-user update collisions is very unlikely and the repercussions of overwriting data is negligible.

Optimistic Concurrency on Update Strategy #2 - Check All Fields

With this strategy, the update command will check that all fields in the row ( usually minus BLOB fields ) are equal to their original values when peforming the update to assure no changes have been made to the original record. A check of the return value of the ExecuteNonQuery Command will tell you if the update actually took place. The return value of the ExecuteNonQuery Command is typically the number of rows affected by the query.

Update Product
Set Name = @Name,
Where ID = @ID
AND Name = @OriginalName
AND Price = @OriginalPrice

This is essentially what CommandBuilder creates when using DataSets and is a strategy that doesn't want to see any changes to the data.

Optimistic Concurrency on Update Strategy #3 - Check Only Changed Fields

Rather than checking all fields in the row to make sure they match their original value, this strategy checks only those fields that are being updated in the command.

Update Product
Set Name = @Name
Where ID = @ID
AND Name = @OriginalName

This strategy only cares that it is not overwriting any data and could care less that other fields in the record may have been changed. This could create an interesting combination of data in the row.

Optimistic Concurrency on Update Strategy #4 - Implement Timestamp

SQL Server has a timestamp ( alias rowversion ) field that is modified everytime a change is made to a record that contains such a field. Therefore, if you add such a field to a table you only have to verify the timestamp record contains the same original value to be assured none of the fields have been changed in the record.

Update Product
Set Name = @Name
Where ID = @ID
AND TimestampID = @TimestampID

This is the same as Strategy #2 above without the need for checking all fields.

Conclusion
Optimistic concurrency has a performance component to it that suggests a higher performing ASP.NET website, so I included it in my series of posts called High Performance ASP.NET Websites Made Easy. Yeah, I could be pushing that statement a bit ;)
There are other methods of achieving optimistic concurrency, but I think the ones above are the most popular. A developer needs to look at the application itself to determine which strategy makes sense. The DataSet, Command Builder, and DataAdapter typically handle this stuff for you using Strategy #2. However, if you work with objects instead of DataSets, you need to handle concurrency issues yourself. If you use an O/R Mapper, make sure you know how your O/R Mapper handles the possibility of collisions during updates.

High Performance ASP.NET Websites Made Easy

Written By David Hayden ( Website / Blog )

ObjectDataSource Control and Concurrency in Multiuser ASP.NET Web Applications

I played with the ObjectDataSource Control a bit this past weekend to understand how it works with update concurrency for multiuser ASP.NET web applications. If you are interested in learning about the fundamentals of concurrency in SQL Server at a high level, you can read my post on it: Concurrency in SQL Server.

Simple ASP.NET Web Application
I put together a simple web page consisting of a GridView connected to an ObjectDataSource using SQL Server Express as the datastore. The GridView is populated by a Customers Table in the database.



Business Classes
The ObjectDataSource Control connects to a business class in your web application for handling the database CRUD activities. I called this class Customers. Optionally, you can have the ObjectDataSource Control pass a class back and forth to Customers as opposed to individual fields. I opted for passing a class back and forth, which I have called Customer.



These classes and methods are specified in the properties of the ObjectDataSource Control:

<asp:ObjectDataSource
ID
="ObjectDataSource1"
TypeName
="Customers"
DataObjectTypeName
="Customer"
DeleteMethod
="DeleteCustomer"
InsertMethod
="InsertCustomer"
SelectMethod
="GetCustomers"
UpdateMethod
="UpdateCustomer"
runat
="server">
...
asp:ObjectDataSource>


ConflictDetection

The ObjectDataSource Control has a property, called ConflictDetection. This sets how you want to handle concurrency in your application.



The default setting is OverwriteChanges, which is the least amount of concurrency control you can have in your application. This is perfect for single user applications or when accidental overwrites of data is acceptable / improbable. For those times when overwriting data is unacceptable, choose CompareAllValues, which will give you much more flexibility and information on checking for changes in the underlying record.

ConflictDetection = OverwriteChangesWhen

I choose OverwriteChanges, the signature of my Update Method looks like the following:



The ObjectDataSource Control passes a single updated Customer class to the method. This class is passed to my data access layer, where any changes made by someone else will be overwritten in the database.

ConflictDetection = CompareAllValuesWhen

I choose CompareAllValues, the signature of my Update Method now looks like the following:




The Update Method accepts 2 Customer Classes - the updated customer information and the original customer information. Hence we can now pass both classes to the Data Access Layer which can create an SQL Update Query that can specify original values in the WHERE Clause to make sure no data gets overwritten ( see my post Concurrency in SQL Server for more information ).

The Update Method expects the format "original_customer" as the name of the original class based on the OldValuesParameterFormatString Property setting of the ObjectDataSource Control which I have specified as follows:

<asp:ObjectDataSource
ID
="ObjectDataSource1"
TypeName
="Customers"
DataObjectTypeName
="Customer"
DeleteMethod
="DeleteCustomer"
InsertMethod
="InsertCustomer"
SelectMethod
="GetCustomers"
UpdateMethod
="UpdateCustomer"
OldValuesParameterFormatString
="original_{0}"
ConflictDetection
="CompareAllValues"
runat
="server">

...
asp:ObjectDataSource>




Conclusion

The ObjectDataSource Control provides the features to help with update concurrency in your multiuser ASP.NET web applications. By changing the ConflictDetection and OldValuesParameterFormatString you can get access to both the original class and updated class data to handle concurrency in any number of ways.Written by David Hayden ( Florida .NET Developer / Blog )


Saturday, July 22, 2006

Best Practice Analyzer for ASP.Net Alpha Released!


By
Joe Morel

One of the most difficult parts of ASP.Net 2.0 application creation is configuring your site correctly. It’s easy enough to actually set the settings, but how do you know the settings are correct? What are the best practices for ASP.Net site configuration, and how do you check that your site is following those practices?

Announcing the Best Practice Analyzer for ASP.Net! It’s currently just an alpha preview version—a shell of the application we hope to turn it into, but it should give you an idea of what we are thinking about. The tool scans the settings for your ASP.Net application from your machine.config, root web.config, and site web.config files and notifies you of any potential errors, warnings, or suggestions to make your site configuration better.

We only have a few rules right now in the engine—this release is mainly to get feedback from the community and see what you think of the tool, but also to start gathering rules from the community. What best practice for ASP.Net configuration do you have to share? Let us know by leaving a message in our forum!

Sharing is the name of the game for this tool—this tool will be part of the Power Toys for Visual Studio, and the libraries we are using to make this an ASP.Net 2.0 focused tool will be 100% Shared Source!

Download the installer for the tool here.

Source

Friday, July 21, 2006

Developing ASP.NET 2.0 Applications using "Atlas" (video)


by Scott Guthrie, General Manager, .NET Development Platform

One of the great features about "Atlas" is how easy it is to take an existing application and add rich client-side behavior to it using "Atlas". In this video demonstration, Scott Guthrie creates a ToDo List application with ASP.NET 2.0 and then adds "Atlas" capabilities to it.(The video length is 18 minutes)

Download this video

Watch other "Atlas" videos