• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 21. Getting Started with Dynamic... > Connecting Dreamweaver to a Database

21.6. Connecting Dreamweaver to a Database

Once you've set up a DSN (page 629), connecting Dreamweaver to the database is straightforward. Start by opening a Web page—any page, even a blank one (because the database connection is stored with the site, not any particular page). Then:

  1. Open the Databases panel by choosing WindowDatabases.

    The Application panel group opens (see Figure 21-12).

    Figure 21-12. The Application panel group contains four panels for working with dynamic database-driven Web sites. The Databases panel is described on page 634. (The Components tab contains advanced features for use with Cold Fusion, JSP and ASP.NET Web sites. It doesn't do anything in the ASP or PHP server models.)

  2. Click the + button at the top right of the panel. From the pop-up menu, choose the appropriate database connection.

    The options you see depend on which server model you've selected. For example, if you're using Cold Fusion, you get a list of all datasources (ColdFusion's term for databases) defined in the Cold Fusion server. JSP developers see a long list of different database options. PHP developers see only MySQL Connection.

    In this tutorial, which uses ASP, your options are Custom Connection String and Data Source Name (DSN). Since you've already created a DSN, choose Data Source Name. The Data Source Name window opens (see Figure 21-13).

    Figure 21-13. The Data Source Name dialog box lets you create a connection to a database using a predefined DSN connection on a Windows machine. The Define button lets you quickly open the Windows ODBC Data Source Administrator box to create a DSN, as described on page 629.


    ASP.NET Note

    Choose OLE DB Connection to open the OLE DB Connection dialog box.

  3. In the Connection Name box, type connCosmo.

    You can actually use any name you want as long as it doesn't start with a number and doesn't contain any characters other than letters, numbers and underscores (_). In this case, conn reminds you that this is a database connection; it makes identifying it easier when you look into the underlying code of the page.

    Next, you'll connect to the database using the DSN you set up previously.

  4. From the DSN menu, choose CosmoClassifieds.

    The Cosmo Farmer database doesn't require a user name and password, so you can leave the User Name and Password boxes blank.


    ASP.NET Note

    In the Connection Name box, type:

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=[path to database];

    Replace the bracketed information—including the brackets—with a path to the .mdb (Access database) file. For example, if you downloaded the files to your C: drive, the path would be C:\DWDynamic\ cosmofarmer.mdb. Skip to step 6.

  5. Make sure that the Using Local DSN button is selected.

    (This option isn't available on the Mac, since a DSN and ASP testing server must reside on a Windows machine.) If you're using a database and testing server on another computer, select Using DSN on Testing Server instead.

  6. Click the Test button to make sure you've connected to the database.

    The message "Connection made successfully" should appear. (If you got an error message, you can refer to page 145 of the Getting Started with Dreamweaver MX booklet or PDF file for help with troubleshooting database connections.)

  7. Click OK to close the dialog box.

    Behind the scenes, Dreamweaver has created a small file, written in the selected server model's programming language and named after the connection name you gave in step 3 (here, connCosmo.asp). Dreamweaver adds this file to every page on the site that communicates with the database. It's in a folder called Connections in the root of the site.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint