home *** CD-ROM | disk | FTP | other *** search
- </SCRIPT><SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
- <!--#INCLUDE FILE="MSGlobal.inc"-->
- ////////////////////////////////////////////////////////////////////
- // //
- // NetObjects Fusion ASP Components //
- // Custom JScript Object: MSDBConnection //
- // //
- ////////////////////////////////////////////////////////////////////
- /*
- Object: MSDBConnection
-
- Version: 1.0 9/23/97
-
- Written By: Application Methods, Inc.
- 6300 Southcenter Blvd.
- Seattle, WA 98188
- (206) 244-2400
- http://www.appmethods.com
-
- DESCRIPTION: This object definition describes properties and methods for a dynamically created
- ASP database connection. This function allows a developer to pass a set of database
- parameters to the object and connect to a database. The parameters are defined as follows
-
-
- Properties:
- name - The name of the MSDBConnection object
- databaseType - Type of connection, e.g. ODBC, native driver, etc. All connections are ODBC for these components.
- ODBCDatabaseType - One of the supported ODBC database types, such as MS Access, MS SQL Server, etc.
- databaseServer - The name of your data source pointing to the appropriate database.
- username - The name of the user allowed DB access
- password - associated pass word for the above user
- globalConn - a string representation of a boolean value indicating whether or not the global.asa file will
- be used to establish the database connection (if true) or one DBConnection component
- per page will be used (false).
-
- Methods:
- connect - Connects to database
- disconnect - Disconnects from database
- connected - Returns whether the database is currently connected
- render - renders hidden visual elements of database component
- emitProperties - emits database component's properties
-
- NOTE: All of the above parameters may not be meaningful based on the type of connection
- that is selected. Please consult the ASP manual and the database vendor for details.
-
- Note: Generation of a number of hidden fields is necessary to pass information
- on to other components. All hidden fields created by this object are prefixed
- with 'amaspHidden_' or 'amaspComponent_'. Developers should never create
- any form element with these prefixes or unexpected results will occur.
-
-
- USAGE:
- <HTML>
- <HEAD>
-
- <!SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
-
- test = new MSDBConnection("test", "ODBC","MS Access", "Northwind","admin","",false);
- if (test.connect()) Response.write("The Database connected properly<BR>")
- else Response.write ("The database did not connect<BR>");
-
- if (database.connect()) write ("The Database is connected<BR>")
- else Response.write ("The Database is not connected<BR>");
-
- write ("The Database is being disconnected<BR>");
- dbResult = test.emitProperties();
- test.render();
-
- dbResult = test.disconnect();
- Response.write ("The database is now disconnected: <B>" + dbResult + "</B><BR>");
-
- <!/SCRIPT>
-
- </HEAD>
- <BODY>
- <%
- // This is only necessary if the component will be used with other components
- MSDBConnection1.render()
- %>
-
- </BODY>
- </HTML>
-
- =====================================================================*/
- function MSDBConnection(name,
- databaseType,
- ODBCDatabaseType,
- databaseServer,
- userName,
- password,
- globalConn)
- {
- // Properties
- this.databaseType = "ODBC"; // All ASP connections are via ODBC
- this.ODBCDatabaseType = ODBCDatabaseType;
- this.databaseServer = databaseServer;
- this.userName = userName;
- this.password = password;
- this.globalConn = globalConn;
- this.connection = null;
- this.name = name;
- Session(this.name) = null;
-
- // Methods
- this.connect = dbConnect;
- this.disconnect = dbDisconnect;
- this.connected = dbConnected;
- this.render = dbRender;
- this.emitProperties = dbEmitProperties;
-
- // Global connect commands removed because done in Global.asa file
- // Set Application("globalConn") here too
- Application("globalConn") = globalConn;
-
- // Write out to session object for use by Query component
- Session("databaseType") = this.databaseType;
- Session("ODBCDatabaseType") = this.ODBCDatabaseType;
-
- } //End MSDBConnection
-
-
-
- // Method - dbConnect()
- // Attempts to make a connection to the database using the Database Object, if the database is not already
- // connected. If the database is already connected, the method returns true.
-
- function dbConnect ()
- {
- if (!this.connected())
- {
- var connection = new Object();
- connection = Server.CreateObject("ADODB.Connection");
- connection.Open(this.databaseServer, this.userName, this.password);
-
- //if (ConnectionErrors(connection) == 1) {
- // Store connection object in Session object for reference by DBQuery component
- Session(this.name) = null;
- Session(this.name) = connection;
- return true;
- //}
- //else
- //return false;
- } // end if (!this.connected())
-
- else return true;
- } //End dbConnect;
-
-
- // Method - dbDisconnect
- // Attempts to disconnect the Database if it's connected. Otherwise returns a true result if the database is already
- // disconnected.
-
- function dbDisconnect ()
- {
- if (this.connected())
- Session(this.name).Close();
- return true;
- } //End dbDisconnect
-
- // Method - dbConnected
- // Attempts to determine the state of the connection. If the connection exists then this function returns true.
- // Otherwise, false is returned.
-
- function dbConnected ()
- {
- if (Session(this.name) != null)
- //{
- // ConnectionErrors() is a VBScript function that checks the connection object's errors collection.
- // This is a workaround for not being able to reference ADO connection objects' errors collections
- // from within JScript functions.
- //if (ConnectionErrors(Session(this.name)) == 1)
- return true;
- //else
- //return false;
- //}
- else
- return false;
- } //End dbConnected
-
- // Method - dbEmitProperties()
- // emits all the object's properties. Used as a debuging tool to verify correct
- // manipulation of the object.
-
- function dbEmitProperties ()
- {
- //debug("Writing MSDBConnection properties...");
- write("\n<BR><B>ASPDBConnection Properties:</B>");
- write("\n<BR>databaseType = " + this.databaseType);
- write("\n<BR>ODBCDatabaseType = " + this.ODBCDatabaseType);
- write("\n<BR>databaseServer = " + this.databaseServer);
- write("\n<BR>userName = " + this.userName);
- write("\n<BR>password = " + this.password);
- write("\n<BR>globalConn = " + this.globalConn);
- write("<BR>");
- return true;
- } //End dbEmitProperties;
-
- // Method - dbRender
- // This method outputs the hidden fields that contain the values of the database
- // connection parameters. This is used by the form handler that corresponds to the
- // UpdateTable component.
-
- function dbRender ()
- {
- // Output the hidden fields for use by Update component
- var pre = "amaspHidden_" + this.name + "_";
- write("\r\n<INPUT NAME = \"" + pre + "ODBCDatabaseType\" VALUE = \"" + this.ODBCDatabaseType + "\" TYPE = \"HIDDEN\">");
- write("\r\n<INPUT NAME = \"" + pre + "databaseType\" VALUE = \"" + this.databaseType + "\" TYPE = \"HIDDEN\">");
- write("\r\n<INPUT NAME = \"" + pre + "databaseServer\" VALUE = \"" + this.databaseServer + "\" TYPE = \"HIDDEN\">");
- write("\r\n<INPUT NAME = \"" + pre + "userName\" VALUE = \"" + this.userName + "\" TYPE = \"HIDDEN\">");
- write("\r\n<INPUT NAME = \"" + pre + "password\" VALUE = \"" + this.password + "\" TYPE = \"HIDDEN\">");
- write("\r\n<INPUT NAME = \"" + pre + "globalConn\" VALUE = \"" + this.globalConn + "\" TYPE = \"HIDDEN\">");
-
-
- } //End dbRender
- </SCRIPT>