Saturday, June 27, 2009
Why I Do Not Like My iPhone
I have an iPhone but I don't see what all the excitement is about.When it became time for me to get a new phone (I'd had my Motorola Slvr for 4 years) I debated about whether I should get an iPhone. The up-front cost was going to be about 100 dollars more than almost any other phone in the store and the requisite data plan was going to be expensive as well. I talked to several co-workers that had iPhones and every one had nothing but good to say. I decided that if I didn't get the iPhone I would probably regret it. So I got an iPhone. And I regret it.
First, I bought my phone in April. The AT&T rep did not say there was a new phone coming out in June. She did mention that there was a new version of software (3.0). And then I didn't really get to use the phone much during the 30 day return period so by the time I figured out just how much I didn't like the phone, it was too late to return it. I am stuck.
So what is it about the iPhone that has me so worked up? Well, there are missing or badly implemented features that just never occurred to me that I should ask about. These just seemed to be givens based on my 25 years of experience with cellular phones. Boy was I wrong. I really underestimated Apple's ability to screw something up. Between the iPhone, iTunes, and Safari, I am now convinced that Apple is absolutely not better than Microsoft at anything except, perhaps, in their ability to, like Microsoft, get some really awesome idea close to reality but stopping just short - and just short in a way that makes the product barely tolerable.
So here's my list of iPhone complaints:
1. You can't take videos using the built-in camera. The iPhone won't do it. When you watch CNN and see all the news videos sent in by viewers or see all the cool videos on YouTube just remember that none of them were done using an iPhone. Virtually any other modern phone or digital still camera also does video. My 4 year old Motorola SLVR did video and the phone I had before that did video. All the phones that my family have do video. An iPhone doesn't. A late breaking update is that the newest iPhone, the 3Gs, will take videos. My iPhone, bought just 2 months ago, and millions others will not. The talk on the Internet from all the experts was that the Apple 3 software that came out a week ago would fix this. It didn't. Big disappointment.
2. In fact, my iPhone from Apple (maker of QuickTime) will not play QuickTime movies. I can download movies from the iStore and play them but I can't create a movie or even download my own movies created on my home digital camera to play on my iPhone. Version 3 did not solve this.
3. Send multimedia text messages. The iPhone won't do it. If I take a still picture (no video) using my iPhone and want to send that picture to my wife on her phone, I can't do it. My 4 year-old SLVR would do it. My iPhone won't. I can only send to her email and, I suppose, she can check it when she gets home. Late breaking update. Version 3 of the iPhone OS will do multimedia text messages with pictures but not with video - if you live outside of the United States. It seems Apple and AT&T are negotiating on allowing it to be used here. Still no multimedia text messages in spite of the promises about Version 3.
4. Receive multimedia text messages. My daughter has a BlackJack. She takes pictures of my grandkids and can send them via multimedia messages to my wife. She can't send them to me. She doesn't have a data plan on her phone and emailing is expensive. I bought an iPhone. I can't receive multimedia text messages of my grandkids. While it is possible for her to email them, why should everyone that wants to send me pictures have to learn to do something special just for me? Well, because I bought an iPhone. Version 3 of the iPhone software allows you to receive multimedia messages with a still picture but not one with video - again, only if you're outside the U.S. In the U.S. you can't do any multimedia text messages. Big disappointment.
5. Delete individual call history items. On any phone I have had since the beginning of cellular phones (I was technical manager and managed cell sites and central offices of a cellular company in 1985) I have been able to either delete individual call history items or at least categories or views of call history items. For instance, if I was looking at dialed calls or received calls and deleted, it would either allow me to delete a single entry or, at most, all of sent calls or received calls. Well, that was until I bought the phone from the pillar of usability, Apple. Now I cannot delete a single entry or any category of entries, the only option is to delete all entries. In fact, I can't even see dialed calls separate from received calls. And if I am in missed calls and delete, it deletes all call history, not just missed calls.
This is a scenario that has happened on more than on occasion in the couple months that I have had my iPhone. Recently, I fat-fingered my contact list and called a business contact to whom I haven't spoken for 3 years and he's no longer with my company. I quickly hung up before he answered but later that day, I accidentally touched the screen in just the wrong ways again and ended up calling him again from my call history. I needed to remove him from my call history. The only way to remove him so I wouldn't accidentally call him was to delete weeks worth of valuable call history.
6. No ability to move files between the iPhone and my PC. Every phone I have had since 2001 has had the ability to share files between the phone and the PC. I have unlimited Internet access on my iPhone but I can't use it to download a file to the phone. Even if I could there is no way to transfer a file to my PC from the phone. My wife's Blackjack can do it. My SLVR could do it.
7. I have family pictures on my PC that I want to copy to my iPhone. iTunes starts by compressing and reducing all your photos before copying them to the phone - compressing and reducing them so that 230MB of originals take 420MB of space on the phone. Definitely something wrong with that picture.
Then, you can only sync to one folder on one PC or lose what's on the iPhone. I had a bunch of pictures on my home PC that I wanted on my phone. As unintuitive as it is, I finally figured out how to get those pictures on my phone by clicking the Photos tab in the Sync screen of iTunes. Then I connected to my laptop wanting to pick up some pictures from there as well. Guess what? You can't do it without losing what's already on your phone! Syncing photos from a second location will always wipe out what's already on your phone! And there's no way to get the sync'd pictures from the phone to your PC for backup before synching to a new location.
8. No tethering. I actually knew this one before buying the phone but was promised it would be fixed in Version 3. It was not. To get around it, I bought a Blackjack that I use just for tethering. We simply share it between family members as needed to help split the cost of the extra phone and services.
9. Another one I knew before hand but is definitely a reason to not buy an iPhone is the lack of an additional memory card. I have an 8GB iPhone. Mostly it is enough for me; preferring a TV screen somewhat larger than 2x3, I don't watch movies or TV on my iPhone and 8GB is a lot of high quality MP3 files. But with the technology available today to not be able to extend the storage of your iPhone by using an additional memory card is simply ludicrous. No matter how cheap memory cards get or how large their capacity becomes, you will never be able to upgrade your iPhone. You'll have to replace it. And if you are on a contract, that could cost you hundreds of dollars. And if you're not on a contract, it will cost you hundreds of dollars unless you are prepared to commit to 2 years of contract. If I want to add 8GB more memory to any of our BlackJacks, it would cost 8 dollars. To add 8GB to my iPhone would be cost anywhere from $350 (used on Craigslist) to $699 (new from AT&T) to buy a 16GB iPhone without a new contract (since I already have a contract and am not eligible for an upgrade).
10. Another issue has come up with an iPhone that many potential buyers, especially those phone buyers who use their phone away from their desks or cars who generate revenue from their phones. I was traveling last week and spent some time playing Mahjong on my phone. Even though I quit playing before getting any low battery warnings, I had consumed enough battery that before my trip was through, and before I had any opportunity to charge my phone, the battery went dead. With any other phone I am aware of or have used, I could simply swap out to my spare battery. With an iPhone that's not possible. So, Mahjong or not (you could easily cause the same dilemma by just being on the phone), an iPhone may not be a good choice if having your phone dead will cost you money.
11. I had great hope that the iPhone OS version 3.0 was going to fix some, most, or all of these issues. Various iPhone sites on the net have been talking about how great 3.0 was going to be. iPhone O.S. 3.0 was going to fix all the issues in the iPhone, solve violence, end crime, and end world hunger. But 3.0 did not solve a single issue that I have with the iPhone. There was nothing at all in it that benefited me beyond finally including a landscape mode keyboard. Even more disappointing was that things that sort of worked - though not great - suddenly got worse.
For instance, the photo album slide show. Pre-3.0, if you tapped an image during the slide show, the show would stop and allow you the option of emailing the image or continuing on with the slide show. The only thing wrong with it before was that if you drug the image right or left you would get the next or previous image based not on the slide show order (which might be random instead of sequential through the folders) but would get the next or previous image based on the file system order. So if you are viewing a slide show in random order and it moves to the next image, then you want to go back to view the image that was just shown previously, you can't get there. Even in random mode, next and previous should show you the next and previous shown, not the next and previous in the file system.
Now when you tap an image, they removed the ability to continue the slide show! Now, instead of dragging to go to previous or next, you have previous and next icons but you don't have a continue or play icon. If you tap the screen, intentionally or accidentally, your only option is to go back to the album list and restart your slide show from the beginning. That is just plain stupid - especially when you're not using the random slide show feature. If you have a thousand images in a slide show and tap the screen at image 500, in order to ever see image 501 you have to restart from image 1 and wait through 500 images again. Did I mention stupid? And guess what? They didn't fix the next and previous links. Those links still don't do next and previous in show order but, instead, only do next and previous in file system order.
Windows Vista slide show, Windows Media Player playlists, and just about anything else that does random playing of anything gets this. In fact, even iTunes gets it. If you navigate backwards or forwards in a random list, move back and forth in the random list, don't switch to the file system list. I guess I must have missed the outcry from the iPhone community asking them to remove the play button from the slide show and to add forward and reverse buttons that don't actually go forward and reverse. What were they thinking?
12. So how is the iPhone at just being a mobile phone? Like my Western Bell Princess Phone from 1974, the iPhone will make calls and receive calls. If that was the whole answer to the question, the iPhone would be ok - but it's not. After all, the reference is not my Princess Phone, it's every other modern cellular phone on the market today.
When a call comes in, the iPhone pops up the picture for the contact calling you. Then it promptly covers it with a menu that allows you to select audio source, keypad, contacts, etc., and there's no way to get rid of it. You can press the home button and the menu goes away but that also gets rid of the contact picture. This is not a huge flaw but it highlights the almost awesome-ness of the iPhone and they just didn't follow through or close the deal.
Speaking of images, you can set a background image for your iPhone. But guess what? It doesn't set a background image at all. When you're on the home screen (the one where you see all the application icons, similar to what we Windows users would call the desktop; the one where we would expect to see the background image) there is no background image. I spent several minutes moving most of the app icons, because I never use them, to the 2nd and 3rd pages of the application list, leaving a mostly blank first page of the app list. Then I added a background image expecting it to show on the background. Guess what? No picture. It turns out that the background picture on the iPhone only shows if you press the home button while the phone is locked - but the default condition of the locked phone is to have the display off. Now I know some will say this is a pretty minor problem and it is. But it shows the lack of direction by the iPhone team. They spent a lot of resources creating a useless background image function. If they weren't going to do it any better than that, I have a whole list of areas where the resources could have been better utilized.
Summary
These issues vary in significance from minor nuisance or frustration up to serious flaws in usability or function. All of them have been known to Apple for a long time from many users on the Apple iPhone forums. Instead of working on these issues that affect those of us who actually buy the phone, Apple spent it's efforts in 3.0 adding 1000 new hooks for developers - most of which are designed to allow developers to sell you stuff from within the program that you already bought from them. In otherwords, the iPhone is nothing more than adware; and you have to pay for the delivery device.
For some people that I have shared these thoughts with, these shortcomings have even been show stoppers. Whether or not to buy an iPhone after knowing of these shortcomings is a personal decision. For many, the things that I do not like about the iPhone are not significant issues. The important thing is to not make the same mistake I did. Don't assume that the iPhone provides functionality or usability that has been standard in phones for years. Hopefully this list will give the reader the opportunity to make a more informed decision.
Trojan.WSUS Part 3
Well, it seems Microsoft has used its trojan, WSUS or Windows Update, to take control of our PCs again. This time, they used it to hide an unneeded, unrequested, and potentially dangerous add-in to Firefox in what was billed as a required security patch for the .Net framework.
The security patch, .Net Framework 3.5 SP1, which came out in February, had a hidden payload in it. In the security patch was an add-in to Firefox designed to enable FireFox users the ability to use Microsoft's One-Click over-the-web software installation. Of course this isn't something users have been clamoring for. It's not something that 95% of Windows users would ever use. When we surf the Internet we're not expecting sites to install software. One-click would allow a site with bad intentions or a site controlled by hackers with bad intentions to install and run software on your pc by simply enticing you to click a malformed or disguised link on their site. Or, if you're gullible enough, they could blatantly display the link as an executable file but that's not necessary at all.
One-click is not something that IE users use. Firefox users, on the other hand, not only don't use it but have generally switched to Firefox to get away from these security risks in IE. Now Microsoft is trying to get Firefox users into the fold. Remember that IE has always been a free product from Microsoft. The value of IE is not in what it does for you but in what it does for Microsoft. How does free software benefit Microsoft? By allowing them to data mine your Internet use or to offer advertisements based upon that data mining. As FireFox penetrates the near monopoly that IE has on the browser market, I expect to see Microsoft take more steps to extend their hooks into Firefox.
What I've told you up to now is not even the worst of it. Not only did Microsoft sneak this add-on into your PC unannounced, but they also disabled the ability to uninstall it. In the Firefox add-ons manager, other extensions have the ability to be uninstalled. This add-on has the uninstall button disabled. Microsoft has said that this is because the .Net add-on is a machine level add-on because it is available to all users and therefore uninstall by a user is inappropriate. But Word is available to all users and it has an uninstall. And the browser is not a machine level application at all; the browser is a per-user application.
Well, finally the uproar has been broad and loud enough that Microsoft has issued a patch - sort of. Now Microsoft has issued a patch to change the add-on to be per-user. That lets users uninstall the patch - for themselves but not for other users. If you have multiple users on your PC, you'll have to uninstall the patch for all users individually. Even worse, if you create a new user account on your PC, the add-on will be automatically added and you'll have to uninstall it again. In other words, this add-on can NOT be uninstalled. It would have been better if Microsoft had left it as a "machine" add-on so when you uninstall it, it is removed completely. I knew right off when I saw that they changed it to per-user that they were, in my opinion, making it even worse by giving you a false sense of security, thinking they had enabled the uninstall when, in fact, you still cannot uninstall the add-on completely.
It seems to me that if the .Net Click-Once add-on had been intended for anything except Microsoft's own good, for example, if it had been done for your benefit, Microsoft would have very proudly announced the add-on rather than sneaking it in at 3:00 AM the way that they did.
Firefox has a web site with listings of available extensions for Firefox. Microsoft has bypassed this standard extension behavior to sneak this in. Firefox has, it seems to me, agreed to support Microsoft in this because there has been no outcry that I have seen from Mozilla (the makers of Firefox) about Microsoft hijacking their browser. It seems to me that this should have been the makings of a giant lawsuit but, instead, I've heard nothing at all from Mozilla.
There was an interesting posting about this on Steve Gibson's site at GRC.com. This is a transcript of a security show with Steve Gibson and Leo Laporte. I have been a fan of Steve's for a dozen years and was a fan of Leo's when he was on Tech-TV before it became the useless-in-my-opinion G4-gamers-tv-with-cop-shows channel.
Friday, January 16, 2009
Improving the Design of Existing Code (Refactoring)
Last week, I had the opportunity to do a presentation on refactoring, using Martin Fowler's book Refactoring as the basis, for the Bartlesville Dot Net Users Group (BDNUG).I offered to do the presentation because I'm passionate both about the topic and about the book. Fowler's book has made a tremendous difference in the quality of my code and in my understanding of object oriented programming.
I created a C# .Net version of the Video Store application used in Chapter 1. If you're new to the book, you might choose to download my starting project to use to work out the refactorings described in Chapter 1. You can also download my presentation.
Friday, June 20, 2008
More Trojan.WSUS
I have about a dozen and a half PCs (half physical, half virtual) on my home network including a WSUS server. That's Windows Server Update Service for non-technical readers. It allows all my PCs to get updated by downloading updates only once. It's all been working fine for at least a year now.A few weeks ago, I approved Windows XP SP3 for installation on one PC - my Media Center 2005 PC (It's the only PC in it's group in WSUS). I wanted to test SP3 on one PC before deploying it on the rest of my XP PCs. The Media Center PC is configured to notify before downloading and before installing. The service pack was downloaded successfully to my WSUS server and I accepted the notification on the Media Center PC to download updates. There were 4 or 5 other updates and then XP SP3.
A few minutes later - maybe half an hour - without thinking, I shut down the WSUS server to complete the installation of updates on the server even though the Media Center PC had not finished updating. I didn't expect this to be a problem; it should be pretty common for a PC to lose contact with its update server or the Microsoft update servers in the middle of downloading updates.
When I turned the WSUS server back on and then rebooted the Media Center, I was unable to get the update download to continue. I tried the usual wuauclt.exe /detect now but it didn't help. Something was wrong but I didn't have time to find out what. Well, tonight I finally got the time to spend on resolving the issue. After much Googling and trying fixes that didn't fix a thing, I finally tried the obvious: ping the WSUS server to make sure I was even communicating with it. The surprising results were:
C:\Documents and Settings\MyUser>ping mywsusbox
Pinging mywsusbox.mshome.net [65.74.135.110] with 32 bytes of data:
Now how in the world did my Media Center PC that has been successfully finding mywsusbox on my network for over a year suddenly begin looking for mywsusbox at 65.74.135.110? I searched hosts files, etc. trying to find out how the requests to mywsusbox were being redirected. I opened group policy editor to see if the specified intranet Microsoft update service location had been changed. It had not. It still said http://mywsusbox/.
Finally I recognized something strange in the results from the ping. having MSHOME in the computer name isn't unusual. As I build and rebuild PCs I have to sometimes set the DNS suffix and since MSHOME is the default workgroup name for XP networks, I didn't think much about it being in the name originally. Then I noticed that it was mywsusbox.mshome.net. The .net part bothered me. Could that have been a real Internet address?
I pinged it and got no response. I did a tracert and found that the IP address routed to a server run by Directapps, Inc. at a hosting company named heraklesdata in Roseville (near Sacramento), California . I'd been HACKED! My PC, without my knowing or without my permission, was looking to an unknown server in California for updates rather than looking at my own WSUS server!
Now I was getting pretty upset. I'm a very careful Internet user and keep my PCs up to date. How in the world had I been hacked? And what other information could they have gotten? We don't do any surfing from the Media Center PC. We try very hard to limit its access to the Internet completely (see http://dalepreston.com/Blog/2007/04/windows-media-player-and-album-art.html). But we do use the Media Center to backup most of the other PCs so its local drives contain a lot of personal data. Had it all been compromised? I was getting frantic.
I started tracking down who this heraklesdata was and to find out what, if anything, mshome.net was. At first, I couldn't find anything useful on either. MSHOME is such a common term in Windows XP networking that Google results appeared rather useless.
Had someone gotten smart and registered the seemingly benign MSHOME.net and created the world's biggest security hole? This question led me to the next obvious step: Whois at http://whois.domaintools.com/mshome.net.
I was relieved, surprised, a little stunned, and a lot disappointed when I found out who owned the domain mshome.net: Microsoft!
Microsoft had, it looks like to me, hijacked my Media Center PC's update process and redirected it to their own server. I suppose I only found this because I turned off my WSUS server mid-update so the nefarious settings could not be removed at the end of the update process without me having become any-the-wiser.
I removed the changed DNS suffix settings using the Network Connections control panel applet (TCPIP advanced settings) and finally my Media Center PC was using my own WSUS server instead of Microsoft's update server in Roseville.
The implications of all of this boggle my mind. Microsoft apparently changed my network settings in a way that could have made my Media Center PC unreachable by other PCs on my local network, could have broken my backup system, and who knows what else. They redirected my PC to their application server without regard to my configuration settings intended to get updates from my own local network instead of from Microsoft on the Internet.
I have limited Internet bandwidth and performance because I am stuck with satellite Internet access in the rural area where I live - that's the reason I have my own update server in the first place. Microsoft bypassed my own server and used my valuable and limited bandwidth for updates without my permission. My wife and I have both complained about the slowness of our home Internet access but blamed our ISP. Now it appears it may not have been the fault of our ISP at all. It is likely that the slowness we have seen may very well be related to one or more of our PCs being redirected to Microsoft's servers without our knowledge or permission.
Now the only unresolved questions are, what else has Microsoft used Trojan.WSUS in order to install on my PC? What software, if any, were they secretly installing on my PC when they redirected me to their server at DirectApps, Inc? What was so important to get onto my PC that they bypassed my own update server and that they would change my network settings without my knowledge - even worse, include my own WSUS server name in their redirected URL so as to obfuscate what they had done?
Sunday, December 23, 2007
To DRM or Not to DRM
I haven't been involved much in the Windows Media Player newsgroups as much as I had planned this year; work and family have just taken all my time. I have found myself there much more the last few weeks, though.
Not much has changed. The same questions are the most frequent questions today as were when Windows Media Player 11 was released. And one of the more frequent topics is DRM, or Digital Rights Management. There are frequent questions from users who have lost access to their protected media or are afraid they might lose access to their protected media.
I don't have much to say on the topic of how to use DRM - I don't use it. What I want to talk about is why not to use DRM and how not to use DRM.
Let me say that all of this discussion is about DRM as it relates to music files, not video DVDs. DVDs are encrypted and protected in the United States by the Digital Millennium Copyright Act or DMCA. There is no way to copy them without DRM in the United States that will not get you prison time - in spite of previous laws that provide for your right to protect your investment and guarantee your fair use of the product you purchased.
There are two primary sources for protected audio files in the Windows environment:
Buying DRM Online
Probably the most common way to get DRM is to buy it intentionally. Most downloaded music (from legitimate download sites) comes as either protected WMA files (Microsoft format) or protected AAC (Apple format) files.There are many problems with both of these formats, DRM and not-DRM:
- Both of these formats, when protection is applied, limit your ability to copy the tracks to other PCs or to burn to CD. They have the ability to limit how many or what type of copies you can make.
- When you use copy protected music, you aren't buying a copy of the music. You are renting it. The copy remains the property of the store where you buy the music. Since they do include limits on how many PCs you can authorize the music for, at some point you will have replaced your computer often enough to run out of authorizations. My wife reads eBooks because of failing eyesight - just normal farsightedness that comes with age - but we are already having to consider limits when thinking of replacing her PC. Since she started reading them, we've upgraded her PC 6 out of 9 possible authorizations.
- What happens when the store you bought the tracks from goes out of business? Or licensing models change? How long will you be able to play your protected track? Microsoft is one of the biggest companies in the software and media business but even they have closed down MSN Music after tens of thousands, if not millions, of tracks were purchased and downloaded.
So far, Microsoft is maintaining the MSN Music license servers and users should be able to access their media. I don't believe it will be that way for long. What happens 10 years from now after those servers have not generated a single cent in new revenue? Will Microsoft still pay for new hardware and upgrades to those servers? And for security patches and for modifying the current licensing software to work with new versions of Windows Server? I seriously doubt it.
And what about other companies other than Microsoft. There have been other companies that sold music online that are no longer in business. Some of those companies did not have the resources from other sectors to maintain the license servers after the online music sales went defunct. Their customers are just out of luck the next time they patch or upgrade Windows Media Player or Windows. Or buy a new PC. There music rental is terminated without recourse. - All online music stores that I know of only sell compressed music - even the ones that sell MP3s. The compression schemes used for most music downloads are lossy - as in a loss of quality over the original Red Book Audio formatted PCM of the CD. The only way to compress digital audio - or to make the file size smaller - is to strip out bits of data. Those missing bits of data generally represent missing sound detail.
(Note, there are lossless compression schemes that strip out data such that it can be rebuilt exactly like the original. For instance, when a specific pattern of data is repeated 12 times, the software can remove 11 repetitions and then include a few bits that tell the decoder to repeat the single remaining instance of that pattern 12 times. These schemes typically offer about 30% compression, not the near 90% compression that MP3 or WMA compression provides. These lossless compression chemes are not typically what you are buying when you buy music online.) - If you create a standard audio CD from your downloaded files the quality will not match the quality of a CD by a long shot. I am pretty tone deaf and I can definitely hear the difference in quality.
If you buy physical CDs, you can rip the CDs to your PC in an uncompressed or lossless compression format and then you can do anything you want with it. If you need a copy of the CD, you can get original quality. If you need MP3 or WMA for a device, you can convert to the best quality MP3 or WMA possible. None of this is possible with the poor quality music available from most online music stores or from peer-to-peer downloading services.
Creating Your own DRM
Once you have bought your own CDs, unfortunately, there is still a way to invite the devil that is DRM into your home. Windows Media Player gives users the option of protecting their own music when they rip their own CDs.The question is to protect whom? From what? Or from whom? And why in the world would you want to? What's in it for you?
Ok, I will admit that the first couple CDs I ripped I did copy protect them. I don't believe in sharing CDs, either getting copies from friends or giving copies to friends - or downloading from peer-to-peer file sharing services. So, the first CDs I ripped, I thought I would do the right thing and protect them so that if anyone ever stole my thousand plus dollar computer, they couldn't get that twenty dollars worth of music. Noble, huh?
No, not noble; ignorant. First off, who am I protecting when I choose to protect the music I rip? Not me. In fact, I am not really even protecting the music labels or the artists. Let's be realistic here. First off, what are the chances that whoever steals my PC likes the same 60's and 70's rock that I listen to? And if they do, and if my music is all protected, they would probably have stolen my CDs when they broke in to steal the PC.
I found out what a big mistake it was to protect those files when, a few weeks later, I reloaded Windows on my PC and found myself unable to listen to any of those tracks!
I started ripping the tracks again with protection before the light finally came on. I wasn't going to go through this again. I stopped what I was doing and started over with no protection. The only thing I found protecting my own files was good for was to protect them from me!
If you don't want to voluntarily surrender your fair-use rights, do two things. If you must rip your CDs as WMA files, make sure the box labeled "Copy protect music" is not checked:

The second thing to do, even better than the first, is to rip your CDs as MP3 or WAV format files. The advantage to either, as related to DRM, is that neither format is capable of supporting DRM so there are no accidents. I have heard anecdotal reports on the Microsoft Windows Media Player newsgroups that there have been occasions where Windows Media Player has failed to play WMA files that should not have had protection. Since MP3 or WAV files can't have protection, that reduces the number of Media Player bugs that are likely to decide unprotected files are protected.
At least use MP3 rather than WMA. Every MP3 player in the world plays MP3 format files - thus the name MP3 player. For the ultimate in compatibility, you just can't beat MP3.
For the ultimate in quality, you just can't beat WAV. Once ripped to WAV format, you can easily convert to any format you wish with no loss of quality, whether that is MP3, AAC, WMA, or some new format yet to be invented.
Wednesday, December 12, 2007
The Second-to-Last How-to-Pass-Arrays-to-Stored-Procedures Article You will Ever Need
The Problem
What About CLR?
The XML Solution
Where's the Array?
Summary
The Problem
It is often desirable to pass an array of values to a SQL Server stored procedure. Perhaps you want to make a similar change to multiple rows in a database. If the rows are sequential by the primary key, you can use BETWEEN. If the rows you want to change are either unordered or random, then you either have to call a procedure multiple times, passing the key to one row with each call, or attempt to pass the unique key value for all rows as an array. Unfortunately, though, SQL (in all versions I know of, not just SQL Server) does not have any provisions for an array data type.That's not a problem, though. Many clever SQL developers have come up with nearly as many different ways of passing arrays to a stored procedure in SQL Server. Most methods involve some sort of delimited string passed as a text or varchar parameter like this pipe-delimited string account numbers from the AdventureWorks sample database:
'AW00000158|AW00000432|AW00000518|AW00000694|AW00000701'Then the developer would creat a loop which would pick the account numbers one at a time from the beginning of the string to the end.
Solutions to the problem have been covered in blogs, web articles many times. That is why, when I needed to pass an array to a stored procedure today, I started with a Google search on the subject. It's not that I didn't know how to do it, I just figured I would find something quick that I could copy-and-paste and save a lot of keystrokes. I got a little excited when I found a match to my search in a Microsoft Knowledge Base article. I thought maybe there would be something new there that I hadn't seen before, considering I didn't remember ever seeing anything on the topic from Microsoft before.
And I was right. The article, How to pass array of values into SQL Server stored procedure using XML and Visual Basic .NET looked very promising and innovative. Rather than the usual delimited string and a loop the article promised to demonstrate passing the array using XML and the OPENXML command available in versions of SQL Server 2000 and later - yes, I had missed this solution for 7 years. The problem is that the article completely fails to deliver on the promise contained in the title. The article contains a lot of lengthy and confusing code that completely obfuscates the intended demonstration. I could only find one reference to an array in the article and that was an array of SqlParameters. I certainly could not find anwhere in the sample code where an array passed to a stored procedure.
So, hopefully this article will simplify and answer the question that led you and me here.
What About CLR?
This article is the "second-to-last" article you will ever need on this subject because this article does not include one great new option with SQL Server 2005 and later. Using CLR integration, you can pass a .Net array to a CLR procedure and call a loop on that array with excellent performance and only a single round trip to the database server.The project that led me to my search today, while being SQL Server 2005 based, does not have CLR integration as an option and that is why you may still need one more article on passing arrays to stored procedures.
This article demonstrates how to use XML to pass an array of values to a stored procedure but it is not an article about XML or XML in SQL Server. For more information about either topic, including specifics on the usage of the commands demonstrated, I suggest searching MSDN or SQL Server BOL.
The XML Solution
So, to pass the array to the stored procedures, we are going to use the OPENXML command. The OPENXML command requires a handle to an XML document and an xpath expression.So first, let's look at some test code. The following SQL statements will generate a simple XML document:
declare @doc varchar(2000)
set @doc =
'<Root>
<Customers AccountNumber="AW00000694" />
<Customers AccountNumber="AW00000701" />
<Customers AccountNumber="AW00000518" />
<Customers AccountNumber="AW00000432" />
<Customers AccountNumber="AW00000158" />
</Root>'
Next use OPENXML to load the XML into memory. The following code instructs SQL Server to load the above document into memory using sp_xml_preparedocument. It then demonstrates how to select from the XML as if it were a data table. Finally, the example unloads the XML from memory using sp_xml_removedocument.
@hDoc, in the following example, is a handle to the XML document provided by sp_xml_preparedocument after loading the XML into memory. Be sure to release the memory as shown because SQL Server only uses a small percentage of of its memory for storing XML and could easily run out of memory otherwise.
-- Load the XML into memory
exec sp_xml_preparedocument @hDoc OUTPUT, @doc
--Select data from the table based on values in XML
SELECT AccountNumber FROM OPENXML (@hdoc, '/Root/Customers', 1)
WITH (AccountNumber VARCHAR(10))
-- Unload the XML from memory
EXEC sp_xml_removedocument @hDoc
The query above returns the selected account numbers, as expected:
AccountNumber
AW00000694
AW00000701
AW00000518
AW00000432
AW00000158
and that list can be used in an IN clause:
-- Load the XML into memory
execsp_xml_preparedocument @hDoc OUTPUT, @doc
--Select data from the table based on values in XML
SELECT c.AccountNumber, c.CustomerID, s.Name AS StoreName, s.SalesPersonID
FROM Sales.Customer c
INNER JOIN Sales.Store s
ON c.CustomerID = s.CustomerId
WHERE c.AccountNumber IN (
SELECT AccountNumber FROM OPENXML (@hdoc, '/Root/Customers', 1)
WITH (AccountNumber VARCHAR(10))
)
-- Unload the XML from memory
EXEC sp_xml_removedocument @hDoc
The query results demonstrate that the list of account numbers yielded from the XML drive the results:
| AccountNumber | CustomerID | StoreName | SalesPersonID |
| AW00000158 | 158 | Rural Sporting Goods | 289 |
| AW00000432 | 432 | Super Sports Store | 275 |
| AW00000518 | 518 | Regional Cycle Shop | 289 |
| AW00000694 | 694 | The Accessories Store | 277 |
| AW00000701 | 701 | Future Bikes | 282 |
Where's the Array?
Having shown how to use an XML document and OPENXML to past a list of values to an SQL Server stored procedure, the only task remaining is to obtain that XML from an array of values - strings in our case. This is simply a matter of creating the XML using your favorite programming language (C# for me) and passing that XML to the stored procedure:
private string CreateXmlDocForSql(string[] accountNumbers)
{
string xmlDoc = "";
xmlDoc += @"<Root>" + System.Environment.NewLine;
for (int count = 0; count < accountNumbers.Length; count++)
{
xmlDoc += "\t<Customers AccountNumber=\"" + accountNumbers[count] + "\" />" + System.Environment.NewLine;
}
xmlDoc += @"</Root>" + System.Environment.NewLine;
return xmlDoc;
}
Summary
You can also use the procedures described here to pass a list of values to be looped in a cursor. Yes, I know. Cursors are evil. I sure don't want to get the lightning storm brought on by my blog post on identity columns and primary keys by talking about cursors. But just remember, a cursor using the XML passed to the procedure as a source cannot possibly have the locking issues normally associated with cursors.
I find this to be a much cleaner method of passing an array of values into a SQL query of any type than to parse a delimited string in a loop. Hopefully it will help you, too.



