- Scalar Functions - Row by row evaluation is never good for performance. Avoid Scalar functions if at all possible.
- Cursors - Cursor engine in SQL Server has extremely horrible performance. There are a lot of better ways to write cursors now.
- The "in" statement. Useful for a few records for a where clause, but will backfire quickly for larger datasets. Instead of using the "in" statement, use the "exists" statement.
- Dynamic SQL. Beware of SQL injection. Use sp_executeSQL and don't parse together statements.
- Lack of Indexes - Queries that don't take advantage of indexes and keys can take any server down.
Monday, October 5, 2009
Wednesday, September 30, 2009
Top T-SQL Commands
Here are some SQL commands that can be a real life-saver that are beyond your basic CRUD statements. Also take note, for .NET developers LINQ should be used whenever possible, but when you've got something complicated, I always seem to turn to one of the commands below. Most of these features were introduced in SQL Server 2005 and 2008.
1.) Pivot and Unpivot - Flip your data around on it's head.
2.) Row_Number - sequential numbers and the ability to restart numbering under any circumstance.
3.) Aggregate Functions (CLR) - If a particular aggregate function hasn't been written yet, you can make one yourself. For example, the aggregate function, "median" or "1st Quartile" is not a built-in function to SQL Server.
4.) Table Value Functions - Incredibly useful in cases where you need to pass in an arguement, but still want the power of a view and stored procedure.
5.) Dynamic SQL - Painful, but extremely useful to build the most optimized and reusable logic.
6.) CLR - Used wisely (ie. NOT for everyday SQL), but if you wanted to do something outside the box. For example, Geo-Code your data or #3's Aggregate Function lets you really customize the database.
7.) For XML Path - Easy way to transform a set of rows into text or xml. Real world example: Use to send custom logs via msdb.dbo.send_dbmail.
8.) Database Triggers - Since Check-in/Check-out is nearly impossible in a database, a database trigger added to a database can track changes and who made the changes.
1.) Pivot and Unpivot - Flip your data around on it's head.
2.) Row_Number - sequential numbers and the ability to restart numbering under any circumstance.
3.) Aggregate Functions (CLR) - If a particular aggregate function hasn't been written yet, you can make one yourself. For example, the aggregate function, "median" or "1st Quartile" is not a built-in function to SQL Server.
4.) Table Value Functions - Incredibly useful in cases where you need to pass in an arguement, but still want the power of a view and stored procedure.
5.) Dynamic SQL - Painful, but extremely useful to build the most optimized and reusable logic.
6.) CLR - Used wisely (ie. NOT for everyday SQL), but if you wanted to do something outside the box. For example, Geo-Code your data or #3's Aggregate Function lets you really customize the database.
7.) For XML Path - Easy way to transform a set of rows into text or xml. Real world example: Use to send custom logs via msdb.dbo.send_dbmail.
8.) Database Triggers - Since Check-in/Check-out is nearly impossible in a database, a database trigger added to a database can track changes and who made the changes.
Labels:
SQL Server T-SQL
Monday, September 21, 2009
Why you should use Twitter
Twitter's value is not in creating tweets, but the opposite, consuming information. Twitter offers a great variety of news resources. I think of twitter as a powerful RSS feed that you can communicate with. As a developer, I follow quite a few developer blogs. Instead of going to their blog, they often will tweet that they have a new post. Tweets provide a short description of the entry, and I can view it if I find it interesting. If you're a .NET developer, here are a few twitter accounts you should follow:
@scottgu - Scott Guthrie - When you think of .NET, you think of Scott.
@shanselman - Scott Hanselman - MSFT MVP
@rickstrahl - Rick Strahl - MSFT MVP
If you're interested in the stock markets, check out:
@WSJ - Wall Street Journal
@JimJCramer - TV Personality Jim Cramer
@stocktwits - Real-time stock conversations
Keep up-to-date on Apple's latest products and rumors, check out:
@iphoneschool - iphone updates and how-to articles
@mactweeter - Latest Apple gossip and news
@scottgu - Scott Guthrie - When you think of .NET, you think of Scott.
@shanselman - Scott Hanselman - MSFT MVP
@rickstrahl - Rick Strahl - MSFT MVP
If you're interested in the stock markets, check out:
@WSJ - Wall Street Journal
@JimJCramer - TV Personality Jim Cramer
@stocktwits - Real-time stock conversations
Keep up-to-date on Apple's latest products and rumors, check out:
@iphoneschool - iphone updates and how-to articles
@mactweeter - Latest Apple gossip and news
Wednesday, August 19, 2009
Choosing the right smart phone for you - iPhone? MyTouch? Palm Pre? Blackberry?
In software development, you typically don't buy a piece of software without doing some analysis on whether it will meet your needs... Your requirements. Recently, I was faced with the challenge of figuring out which smart phone to procure. Narrowing the list down of potential smart phones didn't take too much time. There's the Android MyTouch, Palm Pre, iPhone, Windows Mobile, and various blackberry phones. Price, contract length, and monthly fees are factors, however, buying the smart phone that doesn't do what you want is an even bigger waste of money.
Core Functionality - Your Must have functionality
Core Functionality - Your Must have functionality
- In-Area reception must be good. Look at coverage maps to determine your eligibility.
- Sync Email with Microsoft Outlook
- Sync Email with gmail
- Sync with Microsoft Outlook Calendar and Contacts
- Internet Browsing without the horrible classic "Mobile" look and feel
- Easy to download and listen to music and other multimedia
- Easy to Type and Use
- Touch Screen preference, however it must be able to use Landscape/Portrait views.
- Use existing libraries of Apple iTunes purchases
- Lots of Applications (Facebook, Twitter Apps, News, Stocks, Games, Utilities, etc...)
- Mapping and traffic notifications
- Wifi capable for speedier connections
- Ability to use camera to post pictures on Facebook
- Memory size is upgradable
- Speaker Ability (Phone, Music)
- Good Battery Life
- Tethering
- Sync Multiple calendars
Labels:
iPhone vs. MyTouch vs. Palm Pre
Thursday, August 13, 2009
RAD Development - Balsamiq Review
Balsamiq is a great way to speed up the development of applications for your clients. Before writing any code, Balsamiq is a great way to quickly show stakeholders your thoughts on screen design and layout. This allows you to gather invaluable feedback. By gathering feedback from users early in the process, you can gather better requirements for usability. Previously, I've used tools like PowerPoint, Adobe Photoshop, Adobe Fireworks, and MS Visio to show my thoughts, but these tools were never designed for RAD development. Either the screen designs would look clunky or too good, which left an impression that the site was already done! The "whiteboard" design look and feel that the Balsamiq tool provides is on the level you want to be talking to users during the design and requirements phases. In addition, the control choices are well designed, plentiful, and easy to find.
Whenever you can gather better quality requirements early in the process, the probability of success is much higher.
Whenever you can gather better quality requirements early in the process, the probability of success is much higher.
Labels:
Balsamiq Review
Monday, August 3, 2009
Random Viewstate Errors? Invalid length for a Base-64 char array or Unable to validate data.
I've been noticing random errors on a site and think I've finally got the answer... I've been receiving these "Invalid length for a Base-64 char array" or "Unable to validate data" errors from users in complete randomness. Specifically:
System.FormatException: Invalid length for a Base-64 char array.
System.Web.HttpException: The client disconnected. ---> System.Web.UI.ViewStateException: Invalid viewstate.
and
System.Web.HttpException: Unable to validate data.
System.Web.HttpException: The client disconnected.---> System.Web.UI.ViewStateException: Invalid viewstate.
There's no pattern. I go to the exact same page, refresh, stop, use back keys, etc... and to no avail, no error... According to other blogs and forums, they suggest turning off some security features, which was NOT an option and shouldn't be for you either. My first stop was at my system administrators office. I thought something is meddling with the viewstate. Maybe an intrusion detection or firewall setting was cleaning out some weird characters. After further investigation, nothing.
So looking through the web.config, I took a look at my http handlers. I notice I'm using the RadCompression Utility, (http://www.telerik.com/products/aspnet-ajax/compression.aspx). Apparently, this utility and other similar utilities are notorious for causing these errors. At some point, one of these handlers manipulates the viewstate incorrectly (most likely a bug in the software), that changes the viewstate by attempting to optimize it. When the viewstate is different between callbacks, you'll get on of the errors above.
What ever you do, don't disable .NET inherent security controls like event validation. These controls are there for a reason... Security should always be your #1 priority.
UPDATE: A few months later, I reproduced this problem again, but this time at home. I'm on a wireless connection, and my glorious FIOS wireless router loses connection in the middle of a page refresh.
System.FormatException: Invalid length for a Base-64 char array.
System.Web.HttpException: The client disconnected. ---> System.Web.UI.ViewStateException: Invalid viewstate.
and
System.Web.HttpException: Unable to validate data.
System.Web.HttpException: The client disconnected.---> System.Web.UI.ViewStateException: Invalid viewstate.
There's no pattern. I go to the exact same page, refresh, stop, use back keys, etc... and to no avail, no error... According to other blogs and forums, they suggest turning off some security features, which was NOT an option and shouldn't be for you either. My first stop was at my system administrators office. I thought something is meddling with the viewstate. Maybe an intrusion detection or firewall setting was cleaning out some weird characters. After further investigation, nothing.
So looking through the web.config, I took a look at my http handlers. I notice I'm using the RadCompression Utility, (http://www.telerik.com/products/aspnet-ajax/compression.aspx). Apparently, this utility and other similar utilities are notorious for causing these errors. At some point, one of these handlers manipulates the viewstate incorrectly (most likely a bug in the software), that changes the viewstate by attempting to optimize it. When the viewstate is different between callbacks, you'll get on of the errors above.
What ever you do, don't disable .NET inherent security controls like event validation. These controls are there for a reason... Security should always be your #1 priority.
UPDATE: A few months later, I reproduced this problem again, but this time at home. I'm on a wireless connection, and my glorious FIOS wireless router loses connection in the middle of a page refresh.
Labels:
Viewstate Errors
Subscribe to:
Posts (Atom)