DevelopmentNow Blog
 Wednesday, May 24, 2006

Screencasting is the act of making a movie of what's on your computer screen and making available electronically (usually via the intra- or Internet). Making screencasts can help in a number of ways:

  • You could record demos of software you own for sales & marketing purposes
  • You could record demos of other software for review purposes
  • You could record demos of software or processes for training & support purposes
  • You could record demos of your all-time high frag score on UT2004 for bragging (or getting fired) purposes

Two free tools I've used are Wink and CamStudio. Both will let you record a screencast with audio, add some textboxes & arrows, and output a compressed SWF and HTML file for easy uploading to your web site.

Wink used to be missing audio and other feaures, but they just came out with version 2.0 that includes audio recording, the ability to plop textboxes & objects on your video, and other improvements. It's easy to use and includes some tutorials on how to make your own screencasts. Wink works by recording a series of screenshots and tying them together as keyframes on a Flash movie. The upside of that is that images are clearer and filesizes are smaller, but Wink can't record animation or other nuances. Wink create an EXE from your screencast (good for CDROMS or those small cdrom business cards), uncompressed SWFs (for importing into Flash), and compressed SWFs for sticking on a web site. 

Click here for a sample screencast made with Wink.

CamStudio is based on an open source release from RenderSoft (you can read the whole history on the CamStudio site). While both programs are easy to use, CamStudio is really easy to use because it's simpler -- optionally set a few settings (usually just Region->Region and the SWF/AVI toggle), just click a Record button to record, then click Stop to finish recording. CamStudio actually captures video and compresses it to AVI or Flash, so it'll capture all the animation you need. The downside is that since it's video, you'll notice some grainy compression artifacts, and filesizes are much bigger (the CamStudio sample screencast I made was 4.9mb vs 1.2mb for Wink). Wink seems to have more features then CamStudio, although only CamStudio can convert your movie to an AVI file -- handy if you want to upload your screencast to YouTube or burn a DVD for Uncle Joe to watch on his TV. CamStudio can generate AVIs using a number of codecs (DivX, WM9, etc) if they're installed on your computer.  

Click here for a screencast made with CamStudio.

I suggest checking out both tools. Each will work for most screencasts, although you may prefer one over the other for different things.

May 24, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Tuesday, May 23, 2006

I avoided debugging javascript for a long time because 1) I didn't write a lot of it, and 2) it used to be a pain to do so with Visual Studio. Nowadays it's pretty easy, though, if you know how to do it.

You'll notice that if you open up your ASPX page in Visual Studio and try to set a breakpoint in javascript, you'll usually get a "This is not a valid location for a breakpoint" error. What you need to do is open up the client-side version of the page in Visual Studio and debug that. Here's how:

  • Open Internet Explorer, go to Tools->Internet Options, click the Advanced Tab, and ensure that "Disable script debugging" is unchecked.
  • Fire up your web project in Visual Studio and debug it using Debug->Start Debugging (or F5). IE will open up and display your web site.
  • In IE, navigate to the page whose javascript you want to debug
  • In IE, click the View->Script Debugger->Open menu item. That will open up the current page's html and javascript in Visual Studio.
  • Switch back to Visual Studio. You'll see the page's html and javascript. You can now set breakpoints, etc.
  • Now you can switch back to IE and do whatever you want in the page. Any breakpoints that you set in the previous step will be hit, and you can inspect variables, etc. just like in normal code-behind debugging.

If the above annoys you, another javascript-debugging option is to instead use Firefox and Firebug, which I posted about briefly a few months back. Firebug is a powerful plugin that not only lets you debug javascript, but explore the DOM and watch AJAX requests. You can download it here.

Both approaches (Visual Studio and FireBug) have their merits. I suggest trying them both out to see which works for you.

Code | Tools
May 23, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Wednesday, May 17, 2006

Fresh Installs With Fresh Hardware

Say you just bought a new motherboard, SCSI drive, or RAID card and you want to install a fresh copy of Windows onto it. If the standard Windows OS install contains drivers for it, then you can just boot from the install CD and start installing. Otherwise, you'll need to install the drivers after the install is complete, or during the install.

Installing drivers after you're done installing Windows isn't that bad if you have them on CD and you don't need them during the install. But if you're installing Windows onto a RAID array or a SCSI drive, for example, you'll need those drivers during the install, not after, because you won't be able to complete the installation without them. In my case, I just bought a new RAID card from NewEgg (this one). My plan was to make a RAID 1 (Mirrored) array for redundancy and install a clean copy of Windows onto it. But to do that, I needed the drivers to be available during the install.

Installing Drivers During an Install -- the F6 Floppy Solution

To install the drivers during a Windows install, you need to watch for the message "Press F6 to add a third party SCSI or RAID driver". The message may not be exactly like that depending on which version of Windows you're installing, but it definitely starts with "Press F6." It appears at the bottom of the screen almost right away in the install (while the screen is still blue and in text mode), and you only get a second or two to hit F6 before the opportunity is lost, forcing you to reboot and try again. The F6 method also requires you to have the drivers on a floppy, assuming the drivers will even fit on a floppy, and assuming you even have a floppy drive anymore. A USB Floppy Drive won't always work -- you really need a good ol' fashioned floppy "A:" drive. Blech.

Slipstreaming Your Windows Install CD -- a Cleaner Way

But assume you don't want to go the floppy drive route. You can instead make a "slipstream" version of your Windows install CD, which is basically a copy of the install CD that includes any extra drivers you need (RAID cards, network cards, etc). No floppy drive needed, no pressing F6, no driverless hardware after install, etc. A slipstream CD can also contain hotfixes and service packs, or even be an "unattended" version with all the install questions answered ahead of time. Note that a slipstream CD is not an illegal copy -- you must own a legal version of Windows. For those of you with MSDN subscriptions, your developer disks will work as well.

Slipstreaming used to be a PITA, but nowadays the process is easier thanks to NLite, a free utility that handles most of the dirty work. This quick & dirty guide assumes you know what driver files (.INF) are and have installed drivers and hardware before. It also assumes you know which drivers are the right ones for your hardware and OS.

Using NLite to Make the Slipstream

Anyhow, to make a slimstream CD:

  1. Get your Windows OS Install CD and copy all the files into a folder on your hard drive called c:\windowsinstall or somesuch. If you have an ISO image of the install CD (as you might if you had downloaded the ISO from MSDN), you can instead use a tool like IsoBuster to copy the files from the ISO to c:\windowsinstall. Otherwise you'd have to burn the ISO to a CD and then rip the files. Moving on....
  2. Download and install NLite. You'll need .NET 2.0 in order to run it.
  3. Get the drivers, hotfixes, and service packs you want and save them somewhere on your hard drive. If the drivers are in an EXE (for example, platform drivers for NForce motherboards) you'll need to get them out of the EXE via winzip, or maybe by running the driver EXE and hitting Cancel after the drivers have been extracted but before they've been installed (this works for nforce drivers). Remember that the drivers are where the INF files are.
  4. Run NLite.
  5. Navigate to the folder containing the files from your install cd (e.g. c:\windowsinstall). NLite will scan the files and try to guess what the OS is. If it's correct, click Next.
  6. You'll see a screen listing any previous NLite sessions. If you used it before it'll ask you if you want to load a previous session. In this case we're starting from scratch so click Next.
  7. Now you'll see some toggle buttons where you click on all the things you want to do with your new slipstream CD. I wish NLite had them as checkboxes instead of buttons, but anyhow. If you want to learn about the options, you can read the full NLite guide. In this case we're just integrating some drivers, so click Integrate Drivers and Create a Bootable ISO (so they highlight) and click Next.
  8. You'll see the Integrate Drivers screen. At the bottom, click Install. You'll see two options: Single Driver and Multiple Driver Folder.
  9. Single Driver
    1. If you have one driver in a folder (which is often the case with RAID drivers), choose Single Driver and navigate to the folder, click the appropriate INF file, and click Open.
    2. NLite will auto suggest a mode (PlugNPlay or Textmode) and show the driver(s) below.
    3. Click the appropriate one and click OK. You'll see it added to the list of driver.
  10. Multiple Driver Folder
    1. If you have a bunch of drivers in a single folder (e.g. NForce drivers in C:\NVIDIA\nForceWin2KXP\5.11), click Multiple driver folder.
    2. Navigate to the folder containing all the drivers and click OK. NLite will recurse through that folder and subfolders and display all the drivers it found.
    3. Highlight all the drivers you want to install and click OK. NLite may ask you to pick from a few different drivers as in the Single Driver selection, then finally drop you back to the Integrate Drivers screen.
  11. Now that you've chosen the drivers, click Next. NLite will ask you to confirm, and then it'll start packing all the files together into a single install set, which might take a few minutes. Then click Next.
  12. Now you'll have a chance to specify a label and attributes for a bootable ISO. Enter an ISO Label, leave the attributes alone, and click Make ISO. Choose a target directory and name, click OK, and wait as the ISO is created.
  13. Once your ISO is built, go ahead and burn it to CD or DVD using Nero, Deepburner, or your favorite ISO burning program.

That's it! Now you have a customized Windows OS Install CD that you can use to install a fresh copy of Windows on your new hardware without worrying about hitting F6, missing drivers, installing drivers later, etc.

Note that with certain RAID/SATA drivers there may be extra things you need to do to slipstream them correctly. If you have install problems using the above rough guide, check out the NLite forum or MediaMan's article on Slipstreaming, especially pages 4-5.

OS
May 17, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



Google just blogged about the Google Web Toolkit, a development framework that allows you to write an application in Java and convert it into a working AJAX app. I've always felt that using a toolkit or framework is good when they work -- why reinvent the wheel coding low-level stuff when you can use someone else's to implement your own high-level stuff faster and easier? Unless your product idea is to actually make something low level. As in if you're Google and making a toolkit, say for AJAX apps.

May 17, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Friday, May 12, 2006

As I posted previously, this was going to be a longer post. But it got erased because I clicked the wrong button on my mouse, so you all get the Cliffs Notes version. But that's ok, you're a clever group. All three of you. :)

ASP.NET 2.0 Membership

As you may know, ASP.NET 2.0 comes with ASP.NET 2.0 Application Services, a motley gang of controls and APIs that offer basic building blocks for whipping together sophistication web sites with almost no code at all. For example, let's say you wanted to create a web site that required users to register and log in before accessing certain portions, and be able to have different types of users who could access different areas, and even store personalized information about those users. In the past you'd have to code it all yourself, but not any more. There are a series of APIs that you can access and web controls that work against those APIs. For example,

  • Membership -- stores usernames, passwords, and handles credentials
  • Roles -- groups users in roles
  • Profiles -- lets you store specific information (e.g. favorite color) for users
  • Personalization -- works with Web Parts to customize web controls so users can have their own, personalized web pages (think My Yahoo)

One nice thing is the APIs are simply interfaces to the data -- they don't deal with storing it. Instead, data is persisted via various providers that communicate with the APIs. So you could choose to have the Membership API work with a Membership Provider called XMLMembershipProvider that knew how to store membership data in an XML file. You could then change your mind and switch to using a provider called MySQLMembershipProvider that stored data in a MySQL Database, and you wouldn't need to change any code. Think of the APIs as object oriented interfaces, and the providers as implementations of those interfaces.

So Many Providers, So Little Time

ASP.NET comes with a few built-in providers (SQL Server, SQL Server Express, XML), but there's nothing stopping you from writing your own provider if you want to store the data in a different or proprietary way. You can download Microsoft's Provider Toolkit and have a go. As a bonus, there's a sample Microsoft Access provider for those of you who want to/have to store your information in an Access database.

By default, ASP.NET 2.0 uses a set of providers that store data in a SQL Server Express database located in your web site's App_Data folder. Which is nice in that your site is self-contained and you don't need to have "normal" SQL Server. But it's bad in that SQL Server Express is kinda wimply, many hosting providers don't support it, and it complicates xcopy deployment because the last thing you want to do is copy your development usernames on top of the production set.

If you have SQL Server Standard/Express 2000/2005 available, you may as well use it as the provider. Here's how.

Configure Your SQL Server for Application Services

First you'll need to install some stored procedures and tables in whatever SQL Server database you plan on using. Thankfully, there's a tool that makes this easy. Navigate to C:\Windows\Microsoft.NET\Framework\2.0.<latest> and run aspnet_regsql.exe. Perform the following steps:

  • Click Next.
  • Check "Configure SQL Server for application services" and click Next.
  • Connect to your database server and choose your database from the dropdown. The database you choose will have some tables and procs added for membership et al. Click Next.
  • Click Next to confirm.
  • Wait a bit, and you're done. Click Finish.

If you can't or won't run aspnet_regsql.exe (e.g. your company policies require database changes to be in scripts), there are a number of "Install" .sql files that you or your DBA can run. InstallCommon.sql will need to be run first, and you'll need to change the @dbname variable at the top of each script.

Either way, once the database is configured, you can take a look at what got added -- you'll see a number of databases starting with aspnet_ that will contain the membership information.

Add a SQL Server Provider to Your web.config

Next you want to have ASP.NET use that SQL Server database instead of the Express database.

ASP.NET normally accesses the SQL Server Express database via a provider named "LocalSqlServer," and Scott Guthrie posted a tip on renaming that provider so that it instead points to whatever SQL Server database you want. I don't like doing that because a) it's tricking ASP.NET, and b) you run the risk of confusing people by having a provider named "LocalSqlServer" point to something that may not be local. But, it's easy to do if you want to -- just add the following lines to your web.config's <connectionStrings> section:

<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="YOUR CONNECTION STRING" providerName="System.Data.SqlClient"/>

Anyhow, we're not going to do that. We're going to add explicit lines for our SQL Server database. First ensure there's a connection string in your web.config for your Sql Server.

    <connectionStrings>
        <add name="myConnectionString" connectionString="Data Source=myserver;Initial Catalog=mydatavase;Persist Security Info=True;User ID=myuser;Password=mypassword" providerName="System.Data.SqlClient"/>
    </connectionStrings>

Next, add a Membership section and provider to your web.config's <system.web> section:

<membership>
   <providers>
   <add

      name="MySqlServerMembershipAuthentication"

      connectionStringName="myConnectionString"

      applicationName="/MyApplication"
      description="This is a test database"

      requiresUniqueEmail="false"
      enablePasswordRetrieval="false"

      enablePasswordReset="true"

      requiresQuestionAndAnswer="false"
      passwordFormat="Hashed"

      minRequiredPasswordLength="4"

      minRequiredNonalphanumericCharacters="0"
      type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3500.0, Culture=neutral,

         PublicKeyToken=b03f5f7f11d50a3a" />
   </providers>
</membership>

Use the right connectionStringName for your database, and give it a name you like. The applicationName attribute doesn't have to be your virtual directory, but it should be unique to your application. This allows different applications to have users with the same name in the same database without colliding. You can read more about the attributes on MSDN, but remember that if you choose Encrypted for passwordFormat, you should include your own validation and decryption keys in your web.config like I blogged about previously on passwordFormat.

Lastly, if you plan on having user roles (Admins, Members, Serfs, etc) add a roleManager section to the <system.web> section:

<roleManager enabled="true">
<providers>
<add name="MySqlServerRoleManagerProvider"
connectionStringName="myConnectionString" applicationName="/MyApplication"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>

Tell ASP.NET to Use Your New Providers

Now let's configure ASP.NET to use the new providers you specified. In Visual Studio, click Website->ASP.NET Configuration from the menu. You'll see the ASP.NET Web Site Administration Tool, which allows you to create users and roles, define application settings, and choose providers. Click the Providers tab, then click "Select a different provider or each feature." You should see your new entries there.

Go ahead and select your new providers, and click Test to make sure they're working correctly. If you want to click the other tabs to see what features they offer, go ahead and do so.

Create a User

Let's create a user, just for testing. Click the Security tab. Click Create User, enter some test values (I named my user "test"), and click the Create User button. It'll say whether the user has been successfully created or not. 

Assuming the user was made successfully, close the window, and take a quick look at your web.config file again. You'll see that the attribute defaultProvider has been added to the roleManager and membership tags. You can actually set that value manually in the web.config instead of using the administration tool.

For fun, connect to your SQL Server database again and view the aspnet_Users table. You should see the new user you created. Notice how the user has a unique UserId and ApplicationId, allowing different applications to have their own separate set of users.

 

If you view the aspnet_Applications table you'll see the applicationName you chose in your membership section. The user's password and other information are stored in the aspnet_Membership table. You can poke around a bit more, then delete the user by opening up the Web Site Administration Tool, going to the Security tab, clicking Manage Users, selecting the user and clicking Delete User.

Roles and Controls

Now that you're set up for ASP.NET Membership, you can open up the Administration Tool again to create some Roles and more users and/or you can go ahead and drag Login, LoginView, ChangePassword, etc. controls onto your web forms. You'll find them under the Login section in the Visual Studio toolbox when editing ASPX pages. Most of the Login controls need no code at all -- you can edit their templates, and they'll automatically read the membership information from your web.config and the providers.

Directories in your site can then be protected by creating a web.config inside them and using simple authorization blocks, e.g. inserting

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<authorization>
<allow roles="SomeRole" />
<deny users="*" />
</authorization>
</system.web>
</configuration>

protects a directory from everyone except users in the role "SomeRole."

Conclusion

Well, what started out as a Cliffs Notes got bigger than I expected, but that's OK. Hopefully I've shown you enough to not only free yourself from SQL Server Express, but encourage some of you to dive into the ASP.NET Membership system.

May 12, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



So I have a little rant ... I was typing up a blog article on ASP.NET Membership Providers and how to move that information from SQL Server Express to SQL Server 2005 Standard. And I accidentally (as I sometimes do) clicked the thumb button on my Logitech MX510. By default that button executes the browser's "back" button, but in the case of blogging, instead executes the "undo" feature of the textbox you're typing into. Which means my pages of text disappeared, and of course there's no way to "re-do" the text other than typing it all in again.

So I'm a bit annoyed. And in order to not have that happen, I have to go to logitech.com, download the software, install it, allow the inevitable reboot, then open the software, disable that button, then have the software run in my tray all the time.

So...I'll be back later.

May 12, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Thursday, May 04, 2006

I'm currently working on a property tax consulting startup, and I was noticing that some queries were running slowly. I'm familiar with database indexing, but I wanted to see what the new Database Tuning Advisor that comes with SQL Server 2005 could come up with. It supposedly helps database newbs tune their database without having to know how to create indexes, etc. Seasoned DBAs will probably gasp in horror (with good reason) at automated tuning processes, but what the heck...let's take her for a spin.

Don't Start Without a Trace

The first thing you want to do is create a trace file containing the SQL statements you want analyzed. So fire up SQL Server Profiler, click File->New Trace, and connect to your database. In the trace properties screen you'll want to use the Tuning template, click Save to File, choose a filename, check Server processes trace data, and click Run. See the screenshot below for details.

Now you need to execute the SQL statements that are running slowly. In my case, I just run through a number of test cases in my web application, ensuring realistic database calls. But you could also run SQL statements directly from Query Analyzer or SQL Server Management Studio. You'll need to ensure that your database command timeout is set high enough so your queries finish running instead of rolling back.

Once the SQL statements have finished, stop the trace and exit SQL Server Profiler. You now have a trace file containing all the SQL statements you want tuned. It's a binary file, so don't bother reading it in Notepad, although you can open it up and view it using the Profiler.

Generate Database Tuning Recommendations

Now it's time to tune your database by starting a new Session in the Database Engine Tuning Advisor (DTA -- don't ask why the E is dropped). The DTA groups its recommendations into Sessions. Each session starts out with a Workload (a list of SQL statements to evaluate, e.g. from your trace file) and a set of databases & tables to tune. A Session can either be used to generate tuning recommendations (e.g. Indexes, Statistics, etc), or evaluate pre-specified recommendations and let you know how well they work.

So, open up the DTA -- it'll start making a new Session for you automatically. Connect to your database, select the trace file, choose the database to be tuned from the database dropdown, and put checkboxes next to the databases/tables you want to tune. I didn't bother with the Tuning Options tab, but you can take a look out of curiosity.

Now click Start Analysis at the top, and wait a bit. The Tuning Advisor will run the SQL statements from the trace file, think a bit, and then spit out some recommendations. In my case (see below) it recommended some indexes and recomputing some statistics. It also gave a guesstimate on the speed improvement.

Using the Recommendations

Now you have a set of recommendations, and you have a few choices under the Actions menu item. You can Save Recommendations, which will generate a .sql script file you can apply to your database. You can Apply Recommendations, which just means the Tuning Advisor will apply them to your database, either now or at a specific time (like 2am) in the future. You can also Evaluate Recommendations, allowing you to try them out & see how much they improve performance, without permanently affecting your database. Before Saving, Applying, or Evaluating, you can uncheck any recommendations you want to skip.

I decided to evaluate the recommendations, which creates a new Session (11:32:46 AM) displayed a screen like the one below. Note how the tabs on the top allow you to switch between various Sessions. The tab on the left (the one from 11:08:53 AM) is the first Session that generated the recommendations.

Now that we've set up a "what-if" Session, go ahead and click Start Analysis again, and a Progress screen will come up. The Tuning Advisor will apply the changes, run some comparison tests, undo the changes, and display the results. In the reports tab, you can view reports like Statement detail report (see below) to see how much faster your queries are executing. You can also see how much disk space the indexes take up, and other information.

If you're happy with the results, you can go ahead and Save or Apply the recommendations.

But let's say that you want to try some of the recommendations but not others. If so, you can go back to the original set of recommendations (click its tab, or double click it in the Session Monitor window on the left), check/uncheck some recommendations you want to try, and Evaluate Recommendations again. The ability to play with different sets of recommendations and evaluate them without permanently affecting your database is handy and powerful.

Once I had a set of recommendations whose results I liked, I applied them to my database. I then fired up my application and run through a few test cases, and it ran much faster (as I suspected).

Final Thoughts

The SQL Server Database Tuning Advisor is a nice tool. It probably won't out-tune a skilled DBA, but it does a decent job in recommending indexes. I also like the ability to try "what if" scenarios to evaluate different indexes.

I had a few beefs, however. I didn't like the default names of the recommended indexes, but there was no way to edit them in the GUI. Similarly, there's no way to use the DTA to evaluate your own recommendations -- you can only evaluate recommendations that the DTA comes up with*.

Overall, though, it was a fun tool, and easy to use.

 

* - you can actually use the DTA with custom recommendations (i.e. ones that you came up with) by editing XML files and importing them into the DTA using a command line tool. You can also edit existing DTA recommendations by exporting them to XML, editing them, and re-importing them. I think that's pretty lame that you can't use the GUI for it, but oh well.

May 4, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



I was dealing with an ASP.NET SqlDataSource query that kept timing out, which was annoying because I was trying to run my application through the Database Tuning Advisor (a SQL Server 2005 tool that analyzes trace logs and recommends indexes). The timeouts were preventing me from getting through my whole test case, though.

So, I found a quick solution to setting the timeout value for a SqlDataSource: add a Selecting event handler and put

protected void mySqlDataSource_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
e.Command.Command = 300; // 5 min timeout
}

Easy peasy. :)

May 4, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]