# Tuesday, October 27, 2009
LINQ to SQL is a great idea. It's a fast and easy way to generate a data layer from your SQL schema. With just a few clicks, you can have entity classes generated that you can then query from a repository class (or however you roll).

But what happens when your schema changes? You have to drop your LINQ entities from the diagram and re-add them. Any customizations you have made will be lost. And there are some other pitfalls:
  • Many-to-Many relationships are not supported
  • All your entities are defined in a single, monstrous class
  • You have to fetch records from the database just to delete or update them
  • There is no built-in caching
I was griping about this and someone told me about PLINQO. PLINQO is a set of templates for CodeSmith. There are a couple videos you can watch on www.plinqo.com that explain how to use it. It's pretty easy! You can do the whole thing in under a minute. I had never used CodeSmith or even heard of PLINQO but I figured it all out from watching the videos a few times.

PLINQO offers:
  • Many-to-Many support
  • Entities get their own class files
  • Changes to your SQL schema are magically preserved when you update your classes
  • Deletes and updates are optimized
  • You can detach and reattach entities
  • You can generate astoria services for EASY use with jQuery ajax (sweet!)
  • MUCH MORE
If you like LINQ to SQL but are looking for a way to overcome its shortcomings, PLINQO is definitely the way to go. I have been using it for several months now on multiple projects, and I am very happy with it!

Tuesday, October 27, 2009 12:03:53 PM (Central Standard Time, UTC-06:00)
# Friday, October 23, 2009
The new Baskin Robbins logo is clever. I like it.

But when you write a lot of HTML, sometimes stupid things bother you.


There. That's better.
Friday, October 23, 2009 5:53:20 PM (Central Daylight Time, UTC-05:00)
# Friday, June 26, 2009
They always seem to open maximized, glued to the upper left-hand corner of my monitor. I hate that. After much googling, I found:

http://www.simmonsconsulting.com/2005/09/26/remote-desktop-rdp-window-state/

http://msdn.microsoft.com/en-us/library/ms632612(VS.85).aspx

and

http://blogs.msdn.com/rds/archive/2008/09/02/specifying-the-ts-client-start-location-on-the-virtual-desktop.aspx

These settings work for me:

desktopwidth:i:1600
desktopheight:i:1200
session bpp:i:32

I have a 2560x1600 display, so I like my sessions to be 1600x1200.

winposstr:s:0,1,500,200,2560,1600

1st is always set to zero according to the MS Blog post.
2nd is 1 because I like my remote sessions windowed. Often I have multiple connections open at once.
3rd is 500 because I want my window offset 500 pixels from the left of my primary monitor.
4th is 200 because I want my window offset 200 pixels from the top of my primary monitor.
5th and 6th are kinda funny. They are supposed to represent the bottom right coordinate of the window, so I would expect them to be the top left offset plus the window size. Setting them to 2100 and 1400 should make the window fully sized given my window size and offsets, but I guess it doesn't work that way. Maybe you have to compensate for the frame of the window itself. I found that there is no harm at all in simply setting the size to something larger than the window to assure that it is fully sized. So, I set these values to the size of my largest display.

As the author of the first article mentions, you need to use a text editor that won't corrupt the header of the RDP file. Notepad2 did NOT corrupt it, nor did BeyondCompare 3. TextPad 5.2 did corrupt it.

BeyondCompare 3 was a great way to fix the rest of my RDP files. I just pasted most of the contents of my new, working file over to the files that needed to be fixed, letting only the fulladdress and username fields remain.

Update: Found a cool comparison chart.
Friday, June 26, 2009 11:54:00 AM (Central Daylight Time, UTC-05:00)
# Thursday, June 18, 2009
When I bought my new Dell Studio XPS 16 laptop, the first thing I did was take out the HD and put in a new SSD. Now I've put that original HD into an external eSATA enclosure and I'd like to use all of its space, but there was a parition on it called OEM Partition that was protected, and I could not delete it from the Disk Management utility.

To delete it, I simply ran diskpart.exe, which comes as a part of Windows 7 and I think Windows Vista.

With diskpart running, I first typed:

select disk 1

then:

list partitions

(to make sure I was on the right disk), then:

select partition 1

and finally:

delete partition override

...and that nuked it! In fact, I had the disk manager open while I did this, and it vanished before my eyes. Now I can make a new partition utilizing all of the space on the drive!

Thursday, June 18, 2009 1:39:32 PM (Central Daylight Time, UTC-05:00)
# Friday, May 29, 2009
I've got my Dell Studio XPS 16 laptop up and running the Windows 7 RC.

Stats:

XPS 1640, Intel Core 2 Duo P8700(2.53GHz/1066Mhz FSB/3M L2 Cache)
Obsidian Black High Gloss Finish with Leather XPS 1640
4GB, DDR3, 1067 MHz 2 Dimm forXPS 1640
16.0 inch Wide Screen 16:9 1080p FullHD RGBLED LCD W/2.0 MP, XPS 1640
ATI Mobility RADEON HD 3670 - 512MB
320GB 7200 RPM SATA Hard Drive
Microsoft Windows Vista with SP1 Home Premium Edition 64-bit Edition English
8X DVD+/-RW Slot Load Drive for XPS1640
Integrated High Definition Audio 2.0
Intel WiFi Link 5300 802.11AGN Half Mini Card
56 WHr 6-cell Lithium Ion P Primary Battery, for XPS 1640
Warranty Support,1 Year Extended
Dell Wireless 370 Bluetooth Internal (2.0+Enhanced Data Rate)
Premium HD WLED Display Obsidian Black, Leather 2.0 MP Webcam
Dell WebCam Central 1.0 XPS 1640

Total with Tax: $1,698.46

I've always noticed that when I'm using my laptop (the old one, or even this new one), if I am waiting for anything, it's the hard drive. Despite my heavy development work, the CPU is seldom the bottleneck for me.

Here's a benchmark of the hard disk from HD Tune:



The average Transfer rate is 60.8 MB/sec and the Access time is 24.4 ms. So I sped it up by replacing that HD with an Intel X-25M SSD. Check out the new numbers:




Wow, a 100% improvement in Transfer rate, and a ridiculous improvement in Access time! But this is not the full story. When you're using your computer, the operating system is not usually streaming long contiguous bytes. It's making TONS of teeny tiny little random reads and writes (click here for my source). SSDs are better at this and the Intel X-25M is the highest MLC performer (click here for my source), although OCZ has a great offering.

So let's take a look at those random reads. Here's the data for my Studio XPS 16 with the stock hard drive:



It's doing about 30-40 operations per second, regardless of the transfer size. Remember, your OS does a lot of things at once. It's shooting all over the platter of your hard disk, getting little bits of information. And each time it wants one of those little bits, it needs to move a little arm, and wait for the disk to spin to that spot! But SSDs do not have that limitation. They can read RANDOMLY as quickly as they can read CONTIGUOUSLY. Take a look at that same laptop with the X-25M installed!



Yes, it is literally ORDERS OF MAGNITUDE faster. And you will notice this speed as you boot up faster, log in faster, and launch applications faster.

But, to be fair, SSDs have their limitations. They are notoriously slow when it comes to WRITING. As explained in Andand's article, each time you want to write or overwrite data, you need to perform an erase operation (unless the disk is brand new or was recently wiped). SSD write speed used to be pretty bad, but Intel has raised the bar with the X-25 series, bringing it at least on par with hard drives in most situations. OCZ still has some issues with random writes, but they are improving.

Another SSD limitation is that they wear out more quickly. You can only flash a cell so many times. SSDs wear out faster than Hard Drives. The SSD controller is smart enough to spread your writes evenly throughout its structure, but even then, it will still wear out faster than a hard drive.

Finally, SSDs are far more expensive than hard drives.

Nonetheless, this is the beginning of the end when it comes to hard drives with regard to use as a system volume.
Friday, May 29, 2009 12:12:47 PM (Central Daylight Time, UTC-05:00)
# Wednesday, May 20, 2009
I noticed that my web app, which makes anywhere from one to many MySQL connections per page was running slowly on my new Windows 7 RC laptop. I used dotTrace to compare the page execution to that of my desktop (which runs the app very quickly) and noticed that it was all the MySQL connections that were taking 10x to 100x as long to execute on the laptop.

After a bunch of troubleshooting I finally determined what was causing the performance problem. It was Nod32 4.0. I couldn't just disable Nod32, though. I had to completely uninstall it to cure the MySQL ODBC slowdown!

With Nod32 4.0 installed, some pages were taking 13 seconds to execute.
Without Nod32 4.0 installed, those same pages were taking less than a second to execute.

I observed this behavior on two systems:
  1. Dell Inspiron E1705 w/ Windows 7 RC x86
  2. Dell Studio 16 XPS w/ Windows 7 RC x64 (happened with both 64-bit and 32-bit ODBC drivers, and with both 3.51 and 5.1 versions of each)
Both systems have Windows 7 so this could be a problem only for Windows 7 users with Nod32 4.0. Maybe it's fine with Vista or some other anti-virus application. I hope this helps someone because it took me FOREVER to figure out it was Nod! I sent their support an email explaining all this. Hopefully they will write back with some info. Aside from this, which is a DEALBREAKER, I love Nod32 :(

Wednesday, May 20, 2009 1:02:25 AM (Central Daylight Time, UTC-05:00)
# Wednesday, May 06, 2009
I have a client that needed a text change made in an asp.net web app. Should be easy, right? The problem is that it's an old app, the text was hard-coded in the VB, and the source code is long gone! So how do you edit text that is already in a .NET DLL?

.NET Reflector to the Rescue!
  1. Get .NET Reflector and install it.
  2. Use .NET Reflector to open your assembly.
  3. Expand your assembly, and look for the class that represents the page you would like to edit. In my case it was "viewprintnotice", which represented "viewprintnotice.vb".
  4. Expand that class and click the method you guess the text was set in. I guessed Page_Load.
  5. Right click it and Disassemble.
  6. Did you find the code where the value was set? If so, take note. If not, keep digging until you find it. You can't make the change here, though. To actually edit, you need a plug-in.
  7. Download Reflexil.
  8. Install it.
    1. Close .NET Reflector (this step may not be necessary, actually)
    2. Drop its files into the .NET Reflector directory.
    3. Open .NET Reflector.
    4. View > Add-Ins.
    5. Choose Add, and double-click Reflexil.dll.
  9. Enable Reflexil by going to Tools > Reflexil.
  10. Navigate back to your assembly's class's method that set the text.
  11. Find it under Reflexil's Instructions tab. This may take a bit of digging.
  12. Right-click the instruction, click edit, and make your changes. Update your changes.
  13. Navigate to your dll and click it.
  14. Reflexil will let you save it!
  15. Save it and drop it into your server's bin directory and you've made your text edit.
  16. Take a shower because what you just did was dirty.

Wednesday, May 06, 2009 4:50:11 PM (Central Daylight Time, UTC-05:00)
# Sunday, March 29, 2009
This page tells you how to do it in PHP, and it also tells you what characters need to be escaped. So, converting it to C# was not that hard:
public static string MySqlEscape(this string usString)
{
    if (usString == null)
    {
        return null;
    }
    // SQL Encoding for MySQL Recommended here:
    // http://au.php.net/manual/en/function.mysql-real-escape-string.php
    // it escapes \r, \n, \x00, \x1a, baskslash, single quotes, and double quotes     return Regex.Replace(usString, @"[\r\n\x00\x1a\\'""]", @"\$0");
}
I use it in a static class as an extension method. If you don't speak Regex, what it says is this:
"If you find any of the following list of characters: \r, \n \x00, \x1a, \, ', ", replace them with a backslash followed by themselves."

This will put a backslash before any of the offending characters and make your query safe from SQL Injection. Please don't take my word for it though. If you use it, test it thoroughly.

Sunday, March 29, 2009 5:14:56 PM (Central Standard Time, UTC-06:00)
# Sunday, March 22, 2009

I started by booting the laptop from my Windows 7 Beta Build 7000 (x86) DVD from my MSDN subscription.

I opted to wipe the system and install on a fresh partition. Installation went perfectly. Once I got to the windows desktop, I extracted my Build 7057 ISO with WinRAR and ran setup.exe, following the steps for the upgrade. I'd have just started with this build but I *just* got my hands on it.

The upgrade went smoothly, but it took more reboots than I expected, and reboots happened where I didn't expect them. Oh well, no biggie. Once I got to the desktop, I installed the Vista 32-bit driver for my Radeon Mobility x1400 (downloaded from Dell's site). After a reboot I was at my native 1920x1200 rez.

Next, I installed all recommended and optional updates, which happened to be for my card reader, and the system was fully built and running well! All devices in the device manager are recognized. After that, I installed the Synaptics Touchpad driver (again, I just used the Vista 32-bit driver from Dell's site) and it worked perfectly.

I'm happy with the OS so far. In fact, I'm writing this blog post in Windows 7 right now!


Minor issues I had:
  • I could not join my domain, pendingproductions.com with build 7000. Apparently it's a known issue with long domains. Worked fine with build 7057.
  • My desktop.ini was opening upon every login. I followed these directions to fix that.
2009-03-23 Update: At this point I've installed all my dev and office stuff and it's working great!
  • Office 2007
  • SQL Server 2008 Developer Edition
  • Visual Studio 2008
  • Eset Nod32 Anti-virus version 4
  • WindowClippings (used to take the above screenshot - with alpha channel!)
  • TortoiseSVN
  • VisualSVN
  • HTC Touch Pro (Sprint) phone as modem over USB and Bluetooth
  • Firefox 3
  • WinRAR
Sunday, March 22, 2009 6:49:51 PM (Central Standard Time, UTC-06:00)
# Sunday, March 08, 2009
I have a client that uses Storis as his point-of-sale system. We've got a C#/ASP.NET app running on their intranet that monitors and reports on some other systems, and we wanted to add Storis to the mix. Storis uses IBM UniData as its back end, so this is where we started.

One of the things we got from Storis was a UniData Client CD, which includes an Admin, the UniDK, UniData ODBC, VSG, UniTools, and Dynamic Connect. Included in the UniDK are an OLEDB driver and UniObjects.NET. You might think that UniObjects.NET was the thing to use but that is not what we discovered. We WERE able to pull data out of Storis with UniObjects.NET, but the data was in its native form and SQL was not available. We had to do weird stuff, like query a table for its keys, get them in an array, and then query the table again by its keys. You couldn't just pull back data where Date >= '2009-03-08', for example. At least in no way that was apparent to us.

We installed all that stuff, but it turns out not all of it is necessary. We ended up only using the ODBC driver and VSG.

How we did it:
  1. Install the ODBC Driver
  2. Edit the C:\IBM\UniDK\Config\uci.config file, adding this to the bottom:
    <storis>
    DBMSTYPE = UNIDATA
    network = TCP/IP
    service = udserver
    host = [your storis IP address]
  3. Add an ODBC System DSN
    1. Click Administrative Tools - Data Sources. Note that on a 64-bit system, you will need to access the 32-bit ODBC applet, which you can get to (on Vista x64, for example) in Control Panel -> View 32-Bit Control Panel Items
    2. On the System DSN Tab, Click Add...
    3. Select the IBM UniData ODBC Driver
    4. Click Finish
  4. Configure the DSN
    1. Select your DSN from the list
    2. Click Configure...
    3. Give it a Data Source Name. We went with "StorisUnidata"
    4. For the server, specify "storis", which is the first line you added to the uci.config file above.
    5. Specify your Database name. In the UniData world, they often refer to this as the Account Name, which is a little confusing.
    6. For the User, specify a windows account that can access your database. To eliminate permissions issues, we started with a local system administrator account. We entered that account name under User.
    7. Click OK.
  5. Before you can access your data with SQL, you need to use the Visual Schema Generator to create a SQL Mapping:
    1. Prepare yourself, because this app is a bit ugly :). Think Lotus Notes...
    2. Launch the VSG
    3. This is just like configuring the DSN:
      1. For the server, specify "storis", which is the first line you added to the uci.config file above.
      2. Specify your Database name. In the UniData world, they often refer to this as the Account Name, which is a little confusing.
      3. For the User, specify a windows account that can access your database. To eliminate permissions issues, we started with a local system administrator account. We entered that account name under User.
      4. Enter the password for that windows account.
      5. Click OK.
    4. Click List on the Main Menu, to see all your tables.
    5. Select a table, such as SALES.FLASH.DAILY
    6. Click Open. Note that the dots are illegal in SQL table names, so they will be changed to underscores.
    7. It was not necessary for us to configure any privileges. Possibly because the account was an admin. You may wish to try an Administrator account first as well, then come back here to refine the permissions after you have it working.
    8. Click Map Attributes
    9. Click the columns you want, and hit Add. You may be prompted to rename your column, swapping out illegal characters with underscores.
    10. Click OK.
    11. Click Close.
    12. Hit List on the Main Menu and you should see your SQL Table listed in the right column.
    13. You can exit VSG.
  6. At this point, you should be able to access data in your Storis database via ODBC. So if you're an Access user, you're just about done. You can create a linked table in your usual way, specifying this DSN for your connection information. For .NET programmers, continue:
  7. Your ConnectionString will look something like this: <add key="StorisSystemDsn" value="dsn=StorisUnidata;srv=storis;dbq=YourDatabaseName;uid=YourUserName;pwd=YourPassword;" />
  8. If you're using the Enterprise Library Data Access Application Block (DAAB), your connection string will look more like: <add name="StorisOdbc" connectionString="dsn=StorisUnidata;srv=storis;dbq=YourDatabaseName;uid=YourUserName;pwd=YourPassword;" providerName="System.Data.Odbc" />
  9. You're ready to code!
  10. If your server is 64-bit, your app will not be able to load the 32-bit ODBC driver, and as far as I know, no 64-bit one is available. To get it working in IIS7 on a 64-bit box:
    1. Create a new application pool, and call it something like StorisApp32
    2. In its Advanced Settings, Set Enable 32-Bit Applications to True.
    3. Set your app to use this application pool.
    4. It will now run in 32-bit mode and load the ODBC driver.
    5. You do not have to change the way you compile (no need to specify x86 only, or anything like that).
Grab some data and bind it to a GridView called gvRecords like this:
OdbcConnection odbcConnection = new OdbcConnection(ConfigurationManager.AppSettings["StorisSystemDsn"]);
OdbcDataAdapter odbcDataAdapter = new OdbcDataAdapter("select * from from SALES_FLASH_DAILY", odbcConnection);
DataSet dataSet = new DataSet();
odbcDataAdapter.Fill(dataSet);
gvRecords.DataSource = dataSet.Tables[0];
gvRecords.DataBind();
If using the Enterprise Library, try this:
Database db = DatabaseFactory.CreateDatabase("StorisOdbc");
DbCommand dbCommand = db.GetSqlStringCommand("select * from from SALES_FLASH_DAILY");
DataSet dataSet = db.ExecuteDataSet(dbCommand);
gvRecords.DataSource = dataSet.Tables[0];
gvRecords.DataBind();
That worked for us, and I hope it works for you!

Notes: I was not able to get the OLEDB Driver to work. I kept getting errors about the provider name not being correct. I tried different provider names, even using a script to get the exact name registered with the system, but to no avail. If you get it working, please leave a comment with some instructions :)

Sunday, March 08, 2009 11:25:23 AM (Central Standard Time, UTC-06:00)