In a previous series
of articles, I showed you all the great integration features between the
IBM DB2 Universal Database for Linux, UNIX, and Windows Version 8.x (DB2 UDB)
product and the Microsoft Visual Studio.NET 2003 integrated development
In early June 2006, IBM announced the next release of the DB2
UDB product, DB2 9 (formerly known as DB2 Viper). Part of this
announcement includes the support for Microsoft Visual Studio 2005 and its
accompanying ADO.NET 2.0 driver.
As you may recall, Microsoft announced the Visual Studio
2005 product late in 2005, along with SQL Server 2005. Around the same time,
the DB2 team delivered a beta of the now officially announced integration into
Microsoft Visual Studio 2005 and ADO.NET 2.0.
In another article,
I showed you how to quickly build a Windows Application that bound various
controls (ComboBoxes, DataGrids) using the new Visual Studio 2005 support
announced for DB2 9.
In this article, I want to show you how easy it is to be a
.NET developer and work with DB2 UDB V8 or DB2 9 databases when building a
.NET-based Active Server Pages (ASP.NET) Web site that's backed by a DB2 data
store. Specifically, I will show you how to quickly create a Web page with
Visual Studio 2005 using a DB2 UDB V8 database with this new tooling. (Of course,
I could have easily used a DB2 9 database as well the point here is to show
off the integration of DB2 into the Visual Studio 2005 IDE.)
Note: Before you can create an ASP.NET-based
Web site to which you will bind your DB2 data, a connection to that database must
be defined in the Server Explorer. If you already have a database connection,
continue with the steps outlined in this article. If you don't have a database
connection, refer to the Addendum: Adding a DB2 Data Source section at the
end of this article.
On Your Marks, Get Set....Just Before You Go
In order to follow along with all of the steps outlined in
this article, ensure that your environment has the DB2 SAMPLE database. The
examples in this article use this database (available to both DB2 UDB V8 and
DB2 9 users). If it does not already exist, you can create this database
quickly by entering the db2sampl
command in a Windows command prompt.
Note that the SAMPLE database in DB2 UDB V8 doesn't come
with any referential integrity (RI) constraints so ...? (The SAMPLE database in
DB2 9 has been enhanced with RI constraints as well as a host of other objects
like MDC and MQT tables, and more.)
Visual Studio 2005 will give you some added capabilities
when generating an ASP.NET Web page when it can identify the primary key on a
table. To demonstrate the rich features that Visual Studio 2005 provides for
DB2 Web-based development, add a primary key (which is an online operation in a
DB2 environment) to the EMPLOYEE table by performing the following steps:
that the DB2 instance where the SAMPLE database resides has been started by
entering the db2start command at a
Windows command prompt.
the Control Center by entering the db2cc
command at a Windows command prompt.
the Control Center folders until you locate the Employee table in
the Sample database, right-click this table, and select Alter.
The Alter Table notebook opens.
the Keys tab and click Add Primary. The Define Primary Key window opens, as shown below:
the name of the primary key by typing EMPNO_PK
in the Primary key name field.
the EMPNO column in the Available columns box, click the > button
to move it to the Selected columns box, and then click OK.
are returned to the Define Primary Key window. Click OK.