Custom Connection Strings

Team-Fly    

Macromedia® DreamWeaver® MX Unleashed
By Matthew Pizzi, Zak Ruvalcaba
Table of Contents
Chapter 18.  Dreamweaver MX for Application Development


As you can see, it's quite simple to set up a DSN connection. As mentioned earlier, however, it's not the most robust option. With Dreamweaver MX, you have two choices for creating custom strings: a DSN-less connection and an OLE DB connection.

A connection string contains the name of the driver, the path to the data source, and any additional information that may be needed, such as a username and password.

DSN-less Connection with ASP

When developing Web applications with DSNs, one of the big hassles can be getting the system administrator of the Web server to configure the DSN if you don't have access to that area of the server. If you can't get your DSN configured, your application is then crippled and useless.

Often, developers like to bypass such ordeals by creating a DSN-less connection. With a DSN-less connection, there is no need for such actions to be taken by system administrators.

A DSN-less connection uses the same drivers as its DSN counterpart; however, the DSN-less connection does not rely on a defined Data Source Name.

The syntax for configuring a DSN-less varies a bit from database to database, but all have the same five essential parts:

  • Driver The proper name for the driver can be found at the manufacturer's Web site or locally in your machine's ODBC Administrator.

  • Path to Data Source Depending on the database that you are using, you normally will specify the entire path to the database. This is called the DBQ. However, some databases provide an exception, such as SQL Server and Oracle. The parameter for these databases appears in two parts: an area for both the server name and the database name.

  • User Name If a username is required by the data source, you must provide it in the string. This part is often abbreviated in the connections string as UID.

  • Password If a password is required by the data source, you must provide it in the string. This part is often abbreviated in the connections string as PWD.

  • Provider This is an optional entry, but it refers to the mechanics of the ODBC driver application. The provider for ODBC will always be MSDASQL. Because these two elements go hand in hand, if it is omitted, the connection string will still work.

If you had an Access database called trainsimple.mdb, and you wanted to make a DSN-less connection through a custom string, the string would look like the following:

 Provider=MSDASQL; Driver={Microsoft Access Driver (*.mdb)} ;  DBQ=c:\training\data\trainsimple.mdb; UID=matthewp; PWD=vangogh2; 

You can easily swap out the driver if you were using a SQL Server database.

To create a DSN-less connection in Dreamweaver, follow these steps:

  1. Be sure the Database panel is open by choosing Window, Database.

  2. Click the Add (+) button and choose Custom String from the drop-down menu. This launches the Custom String dialog box, as shown in Figure 18.9.

    Figure 18.9. The Custom String dialog box offers options for creating a custom connection string.

    graphics/18fig09.jpg

  3. Enter a name for the connection. Remember, it's good practice to add the conn prefix so that it's easier to find the connection in the code when debugging.

  4. Type in the connection string as reviewed previously in the Connection String field.

  5. If you're creating a connection for a testing server, choose that option; otherwise, choose Using Driver on This Machine.

  6. If your database permits it, you can limit the available tables. To do this, click the Advanced button. Here you can enter the desired Schema or Catalog.

  7. To make sure your connection was set up properly, click the Test button. This should return an Alert Message saying that the connection was made successfully.

  8. Click OK to exit the Custom Connection String dialog box. Notice that the connection is now available in the Database panel.

Connections for ASP.NET with OLE DB

As you discovered in the previous section, a DSN-less connection does not require an actual Data Source Name. However, DSN-less connections do rely on the actual ODBC drivers. ODBC itself is a translator that relies on OLE DB to make the connection. A more efficient way to communicate with the database is directly through the OLE DB.

An OLE DB connection looks similar to a custom connection string. The exception is that only the Provider parameter, and not the Driver parameter, is included. Here's what a OLE DB connection string would look like, based on a Microsoft Access database called trainsimple.mdb:

 Provider=Microsoft.Jet.OLE DB 4.0;  Data Source= c:\training\data\trainsimple.mdb; 

ASP.NET requires you to use an OLE DB connection, and Dreamweaver MX makes the process simple.

To create an OLE DB connection for ASP.NET in Dreamweaver MX, follow these steps:

  1. Make sure the Database panel is open by choosing Window, Database.

  2. Click the Add (+) button and choose OLE DB for the type of connection from the drop-down menu. The OLE DB Connection dialog box appears, as shown in Figure 18.10.

    Figure 18.10. The OLE DB dialog box offers a large area for you to type in a custom connection string.

    graphics/18fig10.jpg

  3. Provide a name for the connection. Remember to use the prefix conn so that it's easier to identify the connection in the code when debugging. Avoid spaces in your naming conventions.

  4. Type a complete connection string into the Connection String text field. If you want to avoid typing in the connection string, manually click the Build button (Windows only). This launches the dialog box shown in Figure 18.11 and completes each of the tabs with the required information.

    Figure 18.11. The Data Link dialog box offers an easier way to create complicated connection strings.

    graphics/18fig11.jpg

  5. To make sure the connection was properly configured, click the Test button. Dreamweaver will open an alert message informing you whether the connection was a success or not.

  6. When you're done, click OK to exit the OLE DB Connection dialog box. When you return to the Database panel, notice that the new connection is available.

Connections for PHP

Dreamweaver MX's PHP server model supports only MySQL connections. To create a connection with MySQL in Dreamweaver, follow these steps:

  1. Make sure the Database panel is open by choosing Window, Database.

  2. Click the Add (+) button and choose MySQL Connection from the options in the drop-down menu. This opens the MySQL Connection dialog box, as shown in Figure 18.12.

    Figure 18.12. Complete the requested information in the MySQL Connection dialog box to establish a connection with the database.

    graphics/18fig13.jpg

  3. Name the new connection. Remember to use the conn prefix in your naming convention for easier debugging; avoid spacing in your naming conventions, as well.

  4. Enter in the IP address or domain name of your MySQL server. If you're running the server locally on your machine, there's a good chance the domain will be localhost.

  5. Specify the database username in the username text field.

  6. Specify the database password in the password text field.

  7. Type the name of the database into the Database field or click the Select button and choose from a list of options.

  8. To make sure the connection was properly configured, click the Test button. Dreamweaver will open an alert dialog box indicating whether the connection was made successfully.

  9. Click OK to exit the MySQL Connection dialog box. Notice the connection ID now available in the database panel.


    Team-Fly    
    Top


    Macromedia Dreamweaver MX Unleashed
    Macromedia Dreamweaver MX 2004 Unleashed
    ISBN: 0672326310
    EAN: 2147483647
    Year: 2002
    Pages: 321

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net