Ken Spencer |
Windows DNA Then and Now |
Download the code (12KB)
|
Figure 1: Windows DNA Architecture |
Now, what the heck is Windows DNA all about? Figure 1 shows the standard graphic that Microsoft uses. Here is how Microsoft defines Windows DNA: "Microsoft Windows Distributed interNet Applications Architecture is the application development model for the Windows platform." The current version includes:
According to Microsoft, Windows DNA 2000 is "a comprehensive, integrated platform for building and operating state-of-the-art distributed Web applications, as well as the next wave of Internet-based Web services." What does this mean to developers? Windows DNA 2000 is a family of solutions that can be used to solve your development problems. Windows DNA 2000 includes:
You can also mix and match software in your applications using Windows DNA. Today you may be using Visual Basic® 6.0 and SQL Server 7.0 running on Windows NT 4.0. You can port SQL Server 7.0 to Windows 2000 and still have a hot Windows DNA-based application. Then you should be able to migrate to Shiloh, the next version of SQL Server, at some point in the future. Likewise, you can migrate your existing applications to Windows 2000 and take advantage of the other Windows DNA 2000 services. The Tiered Architecture
Applications are broken down into what is typically called a tiered or layered architecture. A tier normally consists of a particular type of software. For instance, in a typical client/server relationship, the client is one tier and the server is the second tier. In reality, the tiers used in any business system will be more vague than a simple list and will likely bleed over from one tier to another. The introduction of COM and DCOM in particular calls for a rethinking of the multitier model. In a typical client/server environment in Visual Basic, the client may be running tier 1, which is the user interface; tier 2 is a database class library (such as ActiveX® Data Objects) implemented as a DLL; the server system is running SQL Server as tier 3; and a fourth tier of agents may be running on the server. Why Use Objects?
So isn't it quicker to just use ASP and ADO to crank out a quick application? I really doubt it in the long run. Why? Good development practices dictate that you should always plan what you are going to do, then execute that plan. One of my favorite old sayings is, "If you fail to plan, you plan to fail." This is what Windows DNA and objects are all about. The Practical Side
Now let's take a look at a simple Windows DNA-centric application. This application will amaze you with its simplicity, but it will also give you a good look at the upside of the technologies. Plus, you can take the code from this column and simply use it since it is generic. |
Figure 3: Form1 DB Component |
Next, to use the component, I added three textboxes and three
labels to Form1 along with a command button (see Figure 3). The controls are named according to the table in Figure 4. The default DSN information points to the Pubs DSN. You should set the DSN string to match your DSN and server security information. Now, open the code window for cmdGo by double-clicking it. Add the code shown here to cmdGo_Click: |
Private Sub cmdGo_Click()
Dim rs As Recordset, txtOut As String
Dim db As db.Database
If txtDSN > "" Then
If txtSelect > "" Then
Set db = CreateObject("db.Database")
Set rs = db.RunWithRS(txtSelect, txtDSN)
Do While Not rs.EOF
txtOut = txtOut & vbCrLf & rs("au_lname")
rs.MoveNext
Loop
txtOutput = txtOut
End If
End If
Set rs = Nothing
Set db = Nothing
End Sub
Now you can run the project containing Form1 (set it as the startup project first by right-clicking the project name in Project Explorer and selecting Set as Startup). You can execute the default settings in the form by clicking Go, or you can dynamically enter your own settings. Looking at the previous code, you should see how easy it is to use the Database class. Now you never need to type all that ADO code again. At this point you might be thinking, "Well that's fine for a Visual Basic-based app, but MIND is about the Internet, not client/server." So lets take a look at the ASP side. First, I started Visual InterDev®, and then created a new ASP page named DatabaseTester.asp. I then added the same controls to this page that I used in the Visual Basic form I created earlier. I used design-time controls (DTCs) in this case; you could also use standard HTML, but your code would be a bit different. The resulting page is shown in Visual InterDev (see Figure 5). Make sure you name the labels for each control exactly as listed in Figure 4. |
Figure 5: Database Test in Visual InterDev |
Also, note the addition of the PageObject DTC. This DTC was added to take advantage of the FirstEntered property. (For more information on PageObject, see my December 1998 and January 1999 Beyond the Browser columns.) I copied the code from the cmdGo_Click event in Form1 and added it to the cmdGo_OnClick event in Database.asp. I had to make a couple of minor tweaks to the code, which is shown in Figure 6. I also created a project reference to the Microsoft ActiveX Data Objects 2.1 Library, as I did in Form1. Next, I added the code in the OnEnter event to load the textboxes with the default values. I also tweaked the code in the OnClick event. These modifications consisted of three changes: I deleted all explicit variable declarations, added .value to all of the textbox references, and added the server prefix to the CreateObject statement. These changes can be seen in Figure 6. Finally, I saved the page and viewed it. Conclusion
So what does all this mean? Well, in the second half of this column, I created the component that contains the Database class. Now whenever you need to use ADO in a Visual Basic, Microsoft Office, C++, Delphi, or ASP application, you can use this class instead of creating all that ADO code again. |
From the December 1999 issue of Microsoft Internet Developer