Please enable JavaScript to view this site.

Navigation: » No topics above this level «

Using DAL in projects with multiple database connections

Scroll Prev Next More

 

Deprecated

Data Access Layer (DAL) is deprecated. While the existing code keeps working, we recommend switching to Database API.

 

In the Enterprise Edition of ASPRunnerPro you can use multiple database connections in a single project. This article explains how you can access data from multiple databases in your events.

dal_mult_connections

Method 1: using DAL functions

There are three options to refer to a table:

 

1. Finds the first matching table by its name in all connections, starting with the primary connection.

 

dal.Table("table")

 

2. Finds the tables by the table name and schema name.

 

dal.TableSchema("table", "schema")

 

3. Finds the table by the table name, schema name and connection name. The schema name can be left empty, and the last parameter is the connection name as it appears on Datasource tables screen.

 

dal.TableSchemaConn("table", "schema", "connection")

 

4. Finds the table by the table name and connection name.

 

dal.TableConn("table", "connection")

 

A complete code example:

 

set data = dal.TableConn("carscars", "cars at localhost").QueryAll()  
while not data.eof  
  Response.Write data("Make") & ", " & data("Model") & "<br>"  
  data.MoveNext  
wend  
data.close : set data=nothing  

Method 2: using free form SQL Queries

Here is how to update all cars where make is Audi and the YearOfMake equals 2002:

 

cman.byName_p1("cars at localhost").query_p1("Update carscars set yearofmake=2002 where make='Audi'")  

See also:

Database API

Using DAL functions in projects with multiple database connections

Connecting to the database

Datasource tables screen

About Data Access Layer