ADO.NET  Examples and Best Practices
for C# Programmers
by William R. Vaughn with Peter Blackburn

Apress: Books for Professionals by Professionals ®

Up
Fix Admin Login


Setup Instructions

The sample code uses the sample "Biblio" database to illustrate most points, however, a few examples demonstrate use of Jet/Access databases. Depending on the example you work with, you need one or more of the following databases:

bulletBiblio -- This SQL Server 2000 database is a greatly expanded version of the Biblio database that ships with Visual Basic 6.0. It's populated with dummy data and sample stored procedures. It's a medium-sized database with 50,000 customers, over 117,000 orders, over 870,000 items, and over 99,000 addresses--spanning about 300 MB of disk space. This test database should help illustrate the performance impact of SELECT * queries with no WHERE clause. The application used to generate the random data for the Customers, Orders, Items, and Addresses tables is included on the CD so you can grow or shrink the data as needed.

All the database files are found in the \Databases folder of this CD.

To Set Up Biblio for SQL Server 2000

Make sure you can log on to SQL Server 2000 with administrative privileges so as to add a database.

  1. Copy the files (NewBiblio_Data.mdf and NewBiblio_Log.ldffrom the CD to your local hard drive in an appropriately named folder.
      
  2. Change the file attributes to read/write.
     
  3. Run SQL Server 2000 Enterprise Manager and open a connection to your target server.
     
  4. Expand the server tree until you can see your list of local databases. If you see Biblio already installed, check with your System Administrator to see why this database is in place. It could be a production database or an example database used in a previous version of this or some other book or it could have already been installed by someone else with access to the server. If this is an old version of the Biblio test/example database, you must rename it or delete it.
     
  5. Use SQL Enterprise Manager to create a new "Admin" LoginID with password "pw" using SQL Server authentication. Change the default database to Pubs; changing the default database to Biblio masks some issues that the examples illustrate.
     
  6. Right-click the Databases node and select All Tasks/Attach Database…
     
  7. Use the button to browse to your local copy of NewBiblio_Data.MDF and click OK. These files are located in the \Databases folder on your CD, but you should move these files to a suitable hard disk prior to attaching. You should see a dialog that points to both the data (MDF) and log (LDF) files. The dialog should also indicate the database is to be installed as "Biblio" and the database owner is "Admin". Your Attach Database dialog should look something like this:

 
 
 
 
Attaching the NewBiblio data files.
  1. Start Query Analyzer, switch the default database to Biblio, and run the fix login script. It's located on the CD in the Databases folder and resets the Biblio database's Admin UserID to match the server's LoginID.

That should do it. You should now have Biblio in your database list and be able to access it.

If you find that the Biblio database is read-only (grayed out), it means you skipped step 2. In this case, you have to detach the database and repeat the steps from step 2 on.

Note: LocalServer DSN
For the ODBC samples, you will need the LocalServer Data Source Name (DSN). You can configure this DSN via the Administrative Tools\Data Sources (ODBC) applet or via the Data View window in VB6. It simply addresses the (local) or "." server. If you're attempting to access a second instance of SQL Server 2000, you have to explicitly reference the instance name as in ".\SS2K2ndInstance" or "myServer\SS2K". This DSN also sets the default database to Biblio.

Support Files

To run some of the examples illustrating use of BLOBs, the folder "Cover Pictures" must be copied from the CD to C:\Cover Pictures. If this is not possible, simply modify the examples that reference these BLOB files to point to the correct path. Yes, the Biblio database stores both BLOB images and their paths in the database.

How Do I Uninstall the Examples?

To remove the sample databases and code, follow these steps:

  1. Open SQL Server Enterprise Manager
      - Right-click the Biblio database icon in your server, and select Delete or simply detach it.
      - Right-click the admin login you created, and select Delete.
     
  2. Delete the C:\ADO folder (or the folder where you copied the files).
     
  3. Delete the C:\Cover Pictures folder.
     
  4. Delete any examples copied to your hard disk.