Posts in category: '.NET'

.NET Developers: Recommend Your Favorite Open-Source Projects Here

See Me Speak at VSLive Orlando 2008

After literally years of trying, I’ve finally succeeded in getting the VSLive folks to let me do a pure open-source talk at the conference. The talk is called Codeplex’s Greatest Hits. The idea is to take a bunch of different cool open-source projects and provide descriptions of them as well as working code demos. The talk is 75 minutes long, so I imagine I’ll have time to do quick demos of between 6 and 8 different projects, of which I already have three or four picked out.

In the spirit of open source, I’d like your help on this. If you’re a .NET developer and you have a favorite open-source tool, post a link to it in the comments. (The tool doesn’t have to be hosted on Codeplex, but it does have to be open-source.) It would help if you also explain why you like it, what you’re using it for, etc. It is totally OK to recommend your own project.

This talk will take place at VSLive Orlando, May 12-16. Once again, the good folks at the conference have provided a discount code for lucky readers of this blog; use the code SOMCM when you sign up for the conference, to get a Gold Passport for $300 off.

kick it on DotNetKicks.com

Slides and Code for Data-Driven ASP.NET Ajax Talk

Even though I was frazzled and exhausted after battling airlines and airports trying to get home yesterday and today, I arrived for VSLive exactly eighteen minutes before my first scheduled talk, which was on using .NET to build Facebook applications. The talk went pretty well and was decently attended but it was challenging to cover the material in a 75-minute talk. If I do this talk again, I’m going to reorganize the content somewhat, maybe include a few diagrams and definitely some more code examples.

My afternoon talk, Data-Driven ASP.NET Ajax, was an updated version of a talk I gave at VSLive NYC last year that was very well-attended and well-received. Here are the slides and code for that talk. Because I used System.Data.SQLite as the database, the demos require no setup or configuration; just open the web site in Visual Studio and peruse to your heart’s content.

Death to Developer Contests

Over on his blog Microsoft’s Dan Fernandez courageously decries the frequent use of developer contests to engage developers and increase momentum for platform adoption. He counted up the number of contests Microsoft is running at the moment: it’s 18. Eighteen different ways to win cash and prizes for doing stuff with various Microsoft products.

Dan thinks this is over the top and I totally agree. When I ran the evangelism team at eBay I resisted the urge to do developer contests for the reasons Dan points out, and when I ran the Yahoo program we didn’t do any; we were more concerned with giving back to the entire community by devoting our very limited time and resources to making new products happen for developers.

Contests are like steroids for platforms. They may pump you up in the short term, but they don’t actually grow the ecosystem. Contests don’t kick off interesting and useful conversations about your platform because they put your developers in competition with each other. More importantly, contests detract resources and focus from where they’re needed.

Throughout the history of American business, the worth of marketers has been measured by the size of the marketing budget (as opposed to the results they might bring to the business). But in a world in which no platform in history has ever provided good enough documentation or code examples for its developers, there’s no excuse to do a single contest.

Creating Facebook Apps Using ASP.NET at VSLive San Francisco

The VSLive conference is an excellent place to become familiar with the latest and greatest technologies for Microsoft platform development. I started speaking at VSLive in 1996 which makes it one of the oldest things I do on a regular basis besides eating/breathing/excreting. VSLive takes place in San Francisco March 30 through April 3.

I am extra excited this year because for the first time in a long time they’ve given me three talks to do, but more importantly, the talks are all on subjects that are fairly out there at least by this conference’s standards (the old management used to be extremely conservative about what you could and couldn’t give talks about). The conference has definitely found an independent editorial voice under its new management and as a result, the talks that I was sure would get laughed off the playground are actually getting accepted.

The Facebook talk was the most challenging to put together and promises to be the most fun. Facebook’s platform is a new, evolving and fairly unusual paradigm for application development — it has some of the elements of traditional web development with a few curve balls that make it feel almost like embedded systems development at times. And since Facebook’s support for PHP is sorta-okay and their support for other languages is not-terrific, things can go from bad to worse for .NET developers who want to create Facebook apps. (It’s surprising that Microsoft doesn’t do much to fill the gap here since they own 11% of Facebook now, but that shouldn’t stop an ambitious hacker from making good software, right?)

You may not want to go to the trouble of learning PHP just to create a Facebook app (although I’m actually doing just that), so I’ve put together some recipes that make it easier to navigate the landscape of Facebook application development in .NET, so that’ll be the focus of my first VSLive talk.

Bonus: If you haven’t registered yet, the good folks at the conference also gave me a promotion code that you can use to save $695 off a Gold Passport for the conference. Use the code SPMCM when you register to get the discount.

Database Queries with Windows Powershell

I haven’t done a serious learning project for a while so this week I decided to play around with Windows Server 2008 and PowerShell. I’ll post some thoughts about Server 2008 soon (at first glance it looks terrific once you get past the fact that IIS is now a "role" instead of something you install). But I wanted to post a PowerShell example first because I wanted to do something with it that I couldn’t find information about anywhere — specifically, perform a database query and dump the contents to the console. (Later we’ll get fancy and dump it to HTML or send it somewhere via email, etc.)

PowerShell can invoke any .NET object, so I knew it was possible to do database stuff with a PowerShell script, but I couldn’t find any examples anywhere, so here’s what I cooked up via trial and error.

The first step is to create a database connection:


[system.reflection.assembly]::LoadWithPartialName("MySql.Data")
$cn = New-Object -TypeName MySql.Data.MySqlClient.MySqlConnection

The syntax to load a .NET assembly in PowerShell is pretty awkward; couldn’t they have provided a Get-Assembly cmdlet? (I suspect that thousands of PowerShell users have already written that one already.) Also, you have to know the assembly name of your ADO.NET provider (which, for MySql, is "MySql.Data," not "MySql.Data.MySqlClient," which was my first guess). The thing to remember is that loading an assembly is syntactically different than including a namespace even though the objective is sort of the same.

Fortunately this is the only part of the process that I didn’t get right the first time, and I had it resolved after a few minutes of experimentation.

I should mention that I’m using the MySql data provider because we use MySql on Approver.com, but you can obviously use any ADO.NET provider you want here. This assumes that your ADO.NET provider is installed in the GAC; if you need to make an explicit reference to an assembly in the file system the syntax is different.

Next, open the database connection:

$cn.ConnectionString = "SERVER=localhost;DATABASE=mydb;UID=xxx;PWD=yyy"
$cn.Open()

If you want, you can check the value of $cn.State here to make sure it worked. Then execute the query:

$cm = New-Object -TypeName MySql.Data.MySqlClient.MySqlCommand
$sql = "SELECT ID, FirstName, LastName FROM Person LIMIT 50"
$cm.Connection = $cn
$cm.CommandText = $sql
$dr = $cm.ExecuteReader()

ADO.NET programmers know that there are lots of ways to do this that require fewer lines of code, but I like to assign everything out explicitly using properties of the ADO.NET Connection and Command objects.

Finally we iterate over the results and close the connection:

while ($dr.Read())
{
    write-host $dr.GetInt32(0) " " $dr.GetString(1) " " $dr.GetString(2)
}
$cn.Close()

This is not too different than what a C# developer is accustomed to, particularly reading out the data. I like that you can just pass a big list of values to write-host without having to explicitly concatenate or convert to strings here. PowerShell figures out what you want to do and does the right thing.

On Approver.com we have a bunch of utilities that we use to monitor system health and site activity (like how many people registered that day, whether people are discovering and using certain features of the site, etc.). Every web site should crunch these numbers frequently (otherwise you have no idea whether the work you’re doing matters to your users).

I think I’m going to eventually migrate our various statistical and maintenance utilities to Powershell. The power of the .NET framework combined with the convenience of script is going to come in handy for a lot of stuff.

Data-Driven ASP.NET Ajax

This week I presented two talks at VSLive in New York. I love speaking at this conference because of its technical focus and because I’ve done it so long — eleven years — there are always a bunch of people I run into at this conference that I only see when I’m there.

I’ve posted here several times about how I’d been trying to get the conference to let me talk about interesting yet sorta-non-mainstream topics such as unit testing (which I pitched to them unsuccessfully back in 2000) and open source (which I succeeded in doing in 2006 with the first talk on MySQL for .NET developers). In the past few years the conference has been much more open to talks on the kind of tools and technologies that are important to me (as well as many other developers for whom Microsoft’s out-of-the-box offerings are not always sufficient).

So my "Data-Driven ASP.NET Ajax" talk is an attempt to take the ASP.NET demonstrations and tutorials that Microsoft provides and tailor them to more real-world scenarios. Here I’m trying to show how a dynamic web application can display data from a database, but also how you can use ASP.NET Ajax to efficiently display large (million-row-plus) data sets, do database transactions, perform server-side data validation without a full page refresh, and so forth. This is a new talk, and I really worked hard on it. I gave it for the first time on Monday afternoon and there were about 120 people in the audience, which was gratifying.

Because I like promoting alternatives to the Microsoft defaults, and because I wanted to be able to give away the source code for my demos and the data without forcing people to go through a big configuration step to get it running on SQL Server, I used System.Data.SQLite as my database. System.Data.SQLite is the .NET implementation of the terrific free embedded database SQLite. Because it’s free (as in public domain) and small, I can distribute the database engine itself along with my demos, which means you don’t have to download or configure a thing to run the demo web site. Just open the project in Visual Studio or drop it into an IIS virtual directory and open index.aspx in your browser.

Here’s the download. It’s about 9 MB because I included the million-row SQLite database I included in my demo, and it also includes the System.Data.SQLite dependency. This version of the site also fixes a problem that I encountered while doing one of the demos (I changed a reference to the master page right before I gave the talk which caused one of the demo pages to barf).

Apache At 56%

Very interesting thread on Digg this morning called "Apache at 56% - what is wrong?" Apparently a number of factors are converging to erode the dominance of the Apache web server (which, as of two years ago, used to run 70% of web sites by some measures). Lots of interesting pro-IIS and .NET comments in the comments (the most vocal Unix/LAMP proponents seem to be embarrassingly out of date on the state of comparable Microsoft products — blinded, no doubt, by their rabid reaction to Microsoft businesses practices in the 1990s).

Several people pointed out that IIS today is very secure, performs well and is easier to configure (and the upcoming IIS7 adds a number of compelling features that bring it closer to feature parity with Apache). In discussions like this somebody always brings up the "free beer" argument (that Apache costs $0), but they neglect to mention that you can get the web server edition of Windows for just $300 now, and IIS/.NET is a more productive stack for developers by far. (I could easily burn more than $300 worth of time getting Apache configuration figured out.)

Cgen: Simplest .NET/MySQL Relational Wrapper That Could Possibly Work

Last week I attended and spoke at the MySQL conference. Some of the talks, particularly the ones that targeted system administrators rather than developers were over my head, but that’s useful information in itself — it serves as a reminder that sometime soon I’ll need to either learn the finer points of big-time MySQL system administrator or hire somebody who does.

It was particularly fun giving a talk on .NET to MySQL guys just two weeks after I finished giving a talk on MySQL to a room full of .NET guys. It was also fun seeing my client Alfresco and hanging out with them in their booth, where they were doing demos and fielding lots of inquiries.

I’m just now getting around to firing up the blog-o-matic in earnest after four weeks of more or less non-stop conference-going, but I wanted to mention that I’ve released the tool that we use to create the data access layer. It’s called Cgen, and it lives here.

The idea behind Cgen is that you create an XML document that represents your database schema, and Cgen (which is packaged as a command-line tool written in C#) spits out a bunch of classes that make it easy to do the basic create, read, update, and delete operations that represent 80% of all database-driven applications. (For the remaining 20% of the data access code you’d need to write, the tool generates subclasses that you can add your own code to.) You can then compile these classes as a .DLL or, if you’re making an ASP.NET 2.0 web application you can just dump the classes into the application’s App_Code folder and .NET will figure out how to compile the classes.

We use code generated by Cgen as our data access layer for Approver.com. It has worked splendidly and saves us a bunch of time. At the same time, Cgen doesn’t have a ton of bells and whistles. I realize that this is probably the one millionth object/relational code generator in the history of software development. I took a look at other object/relational mappers like SubSonic, and I used NHibernate on an intranet project I did at Yahoo in 2005. But for Approver I wanted a tool so simple that you didn’t spend more time learning the tool than you would have spent writing the code yourself. I also needed something with good support for .NET 2.0 and MySql (which was difficult to find in March 2006 when I started using MySQL).

Rob Conery Wants Your Questions about Microsoft and Open Source

Rob heads up an open source product called Subsonic; he’s been invited to speak on a panel at Microsoft’s MIX ‘07 and he’s asking folks to pass questions along pertaining to Microsoft development and open source that might be useful to discuss on the panel.

It was most excellent to see that Miguel de Icaza will also be speaking on the panel (even though, regrettably I won’t be at MIX this year so I won’t get to attend this panel). In years past Microsoft banned all discussion of Mono from the allegedly community-driven portions of its Professional Developer Conferences, so it’s neat to see that Miguel will finally be given a soap box now that his employer and Microsoft have achieved a rapproachment.

Update: Video of the session is now online here.

New Version of MySQL .NET Connector

A while back I posted that the 5.x line of MySQL connectors was a bit too garden-fresh for production use. Fortunately Reggie and team have quickly released a new version: here are the details.

From the release notes it looks like they might have resolved the problem that I was having. I’m still using the 1.0.9 connector for now but I’ll be testing the new 5.0.5 version as soon as I get some time in hopes that I can show off MySQL/Visual Studio integration at VSLive in a few weeks.

Update: Reggie says that 5.0.5 isn’t soup yet, either: details here.

MySQL .NET Connector Madness

As I’ve been writing about here for a while, my big learning project of 2006 was to pick up MySQL and to build a web site using ASP.NET with MySQL as the back-end. This went really well, better than I could have expected. For someone who has experience with SQL Server, the learning curve isn’t too bad, and MySQL clearly did a lot of things with developer productivity in mind.

One of the things that I try to do when I write articles or do talks on technologies is to use the latest versions of everything, so when I started preparing my upcoming VSLive talk, I upgraded everything on my dev boxes, including the server, the ADO.NET providers, etc.

MySQL provides two sets of "connectors" for .NET developers. (.NET developers know these as "ADO.NET providers".) The connectors in the 1.0 line are more stable, but they don’t support the new features of ADO.NET that came out in .NET 2.0, which means that stuff like declarative data sources as well as the MySQL Visual Studio add-in won’t work — all this stuff expects to see the 5.x connector installed in the global assembly cache.

Unfortunately, the 5.x line of connectors isn’t ready for prime time yet — some folks (including me) have had problems consistently connecting to the server with the latest 5.0.x connector. So yesterday I backed out the upgrade and I’m using the 1.0.9 connector for now. I should mention that this version of the connector is also live in production on Approver.com right now and it’s 100% solid.

To their credit, Reggie and the MySQL team do a great job of providing information and feedback when issues like this come up, as they inevitably do — I feel like I can get way more information from MySQL than I ever could from Microsoft or Oracle in situations like this. So I’ll hang in there, and if they can get another rev of the 5.x connector I’ll give that a whirl before my VSLive talk.

Update: They released a new version of the 5.x connector that may fix this problem.

Quick Keyboard Toggle Between Designer and Code View in Visual Studio

I don’t use Dreamweaver to build web sites anymore since they gave up on supporting ASP.NET, but a few years back it was my favorite tool — for all its wrinkles, in the 1999-2003 timeframe, Dreamweaver was better than Visual Studio for building web sites. I’m looking forward to seeing what Adobe does with the Dreamweaver product in its next release, whenever that might be.

One extremely useful keyboard shortcut that stuck in my brain from my years of using Dreamweaver is Ctrl+` (that’s control backtick, the button on the left side of the keyboard where the tilde is located). It lets you quickly toggle between visual display of your page and code view. I’m not sure if there’s an equivalent default keyboard shortcut in Visual Studio, but the command certainly exists and you can assign it to Ctrl+` pretty easily if you still have Dreamweaver brain cells attached to this behavior.

Vstudiocustomizekeyboard

To do this, in Visual Studio 2005, open a web page and open the Tools, Customize menu. Click on the Keyboard button at the bottom of the dialog, then scroll down to select the View.ToggleDesigner command. Then click in the text box labeled "Press shortcut keys" and type Ctrl+`. Bingo, you now have the same keyboard shortcut to toggle between code view and the visual page designer.

Outline of My MySQL Talk at VSLive

Here’s a list of slides I’m developing for the MySQL talk I’m giving at VSLive next month. This talk is intended for developers who are proficient with .NET and some kind of relational database but with with little or no exposure to MySQL. I am pretty sure that the talk is going to be 60 minutes in duration, so 30-40 slides should be about right.

Did I leave anything important out? Let me know in comments — thanks!

  1. What is MySQL?
  2. Meta: About Open Source Software
  3. Obtaining MySQL
  4. Installing MySQL
  5. Configuration
  6. Jeffrey’s my.ini File
  7. Gotcha: Security Settings
  8. Command-Line Tools
  9. MySQL GUI Tools
  10. Visual Studio Integration
  11. MySQL Administrator
  12. MySQL Query Browser
  13. Creating a schema
  14. Pluggable Storage Engines
  15. Data Types
  16. Enumerations
  17. Gotcha: Set DATETIME Defaults
  18. Unicode Support
  19. MySQL Query Manager
  20. MySQL ODBC Driver ("it exists")
  21. MySQL ADO.NET Provider
  22. Creating a DataReader
  23. DataReader with Parameters
  24. DataSet
  25. Subselects
  26. Use LIMIT N instead of TOP N
  27. Stored Procedures
  28. Transactions
  29. Triggers
  30. Clustering
  31. Replication
  32. Architecting for Scalability
  33. References

Installing the MySQL ADO.NET Connector into the Global Assembly Cache

This morning I sat through a MySQL webinar on Visual Studio tools for MySQL presented by the most excellent Reggie Burnett.

One of the questions that came up after the talk pertained to installation problems on Windows. (I should preface all this by saying that MySQL, the database server, has a good installer and is a snap to get running on Windows.)

I don’t usually use MySQL’s pre-compiled installers on Windows — now that I sorta know what I’m doing, I find it’s usually faster to set up MySQL and its attendant GUI tools without installers. And MySQL supports the notion of downloadable zips without binary installer cruft, which I really like, particularly in situations where you just need to yank one file out of the distribution (like documentation) without having to go through a whole big install.

But for those of us who eschew installers, there’s a trick with the MySQL tools for Visual Studio: the installer for the Visual Studio add-in apparently expects to find the MySQL ADO.NET provider (which MySQL refers to as "Connector/Net") in the Global Assembly Cache. If it doesn’t find the provider in the GAC, the add-in won’t run.

I was dimly aware of the existence of the GAC but I’d never needed to do anything with it myself in the real world (aside from mentioning it in my books). This isn’t a huge inconvenience, though. First you just need to locate a command-line utility called gacutil.exe on your machine (mine’s in the SDK directory under Visual Studio 8, but yours might be somewhere different depending on what tools you’re using).

Next you’ll need to locate MySql.Data.dll on your machine. This file can be located anywhere if you’re difficult like me and you don’t use an installer.

So, the entire command line I needed to use to install the MySQL provider in the GAC was:

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /i "C:\Program Files\MySQL\Connector.NET 5.0.3\Driver\bin\net-2.0\release\MySql.Data.dll"

(The /i switch means "install".)

This is certainly not brain surgery but hopefully putting all this in writing will save others some time.

More posts in MySQL:

“eBay Basics” C# Example

For the (numerous) user group talks I’ve been doing in the past few months, I’ve spent most of my time with one demo that shows three common eBay API calls — GeteBayOfficialTime (the “hello world” of eBay programming), AddItem, and GetSearchResults. Several people have asked me to make this demo available, so here you go:

Update: I finally got around to revising this to support the authentication system we rolled out last year — you can now find this example on our examples site.

eBay Luvs Visual Basic Developers

Had a great time speaking in Redmond last night to the VB .NET user group on the Microsoft campus. Mister Robert Green, VB .NET evangelist extrordinaire, reminded me that my article on building an eBay search app using VB .NET is featured this week on the Visual Basic Developer Center. Cool!

I’m in the middle of writing another article that will cover programming to eBay’s product taxonomy, a topic which I touched on briefly in my talk last night but don’t have a great code demo for yet. The basic problem is this: how do you make a database of 20 million products browseable? The answer to date has been to create a hierarchical taxonomy of 30,000-45,000 nodes called product categories and assign each listing to one or two categories. This isn’t a great choice when what you’re looking for is a pair of tickets to see the Giants play on September 21 — there’s no September 21 category for Tickets, and the concept of “September 21″ would suck mightily as a keyword search, but you actually *can* ask eBay to show you all the baseball games slated to take place on September 21. The way that eBay does this and the way you can take advantage of this as a programmer will be the topic of my next oeuvre.

VSLive, Windows Mobile 2003 for the i700, Vacation

Had a great couple of days in the eBay Developers Program booth at VSLive this week. Most common comment we heard: “I didn’t even know eBay had a developer program.” (We’ll fix that.) My team is there today, so if you’re at the show, stop by the booth and say hi.

At the show I got confirmation from Verizon and Samsung that the SPH-i700 will indeed be upgradable to Windows Mobile 2003, woo hoo! They said that owners will be able to take the PDA phones in to a Verizon store to get the upgrade.

I’m moblogging this from the airport; I’m off for a few days of baseball spring training in Arizona.

eBay SDK Article on OnDotNet.com

I’ve got an article up today on O’Reilly’s OnDotNet.com Web site. It’s on creating eBay applications using our SDK for .NET. It basically takes the tossed-off snippet I posted here back in September and explains it in more detail, building it out into a glorious explanation of how to list items and search on eBay using software you write yourself. I only had space to cover the tip of the iceberg, but hopefully from the article you can get a sense of how things go.

Remember that if you aren’t all about .NET, you can still write eBay apps, ’cause we have a cross-platform XML-over-HTTP API as well. All the goodness is at http://developer.ebay.com.

Converting from GMT in .NET

Patrick Steele posts a neat tip about how to convert from Greenwich Mean Time to local time using .NET. As it happens, it’s crazy easy.

This tip is particularly useful for eBay API developers because 1) the current time is very meaningful when you’re buying and selling in an auction format, and 2) all of the timestamps returned by calls to eBay API are in GMT.

eBay SDK ‘hello world’ in C#

I figured that since I addressed one of the most remote edge cases of eBay API development the other day, I should close the loop by posting one of the most common cases (using the SDK with C#).

Using the SDK for Windows is cake compared to the API way (which takes about 100 lines of code to do the same thing, forcing you to use MSXML to handle XML parsing and the HTTP request and response). This SDK version of GeteBayOfficialTime also has the benefit of returning a DateTime type, whereas the API way returns an ISO date that you have to parse to play nice with VB6 or .NET.

Update:You can find this example on our code examples site.