ADO (ActiveX Data Objects) is a standard interface.
ADO is an application programmer’s interface (API) that provides developers with an easy way to access the underlying OLE DB data access interface. It’s part of Microsoft’s overall Component Object Model (COM) strategy and, as such, works in a variety of environments ranging from Visual Basic to Active Server Pages.
ADO is an application programmer’s interface (API) that provides developers with an easy way to access the underlying OLE DB data access interface. It’s part of Microsoft’s overall Component Object Model (COM) strategy and, as such, works in a variety of environments ranging from Visual Basic to Active Server Pages.
The ADO object model is actually quite simple — there are only six total objects:
The Connection object sets up a link between your program and the data source. This object contains all of the necessary configuration information and acts as a gateway for all of the other ADO objects. The Connection object is mandatory — all implementations of ADO must support it.
Each Connection object may have an associated collection of Error objects. ADO utilizes this collection when the connection returns more than one error message at a time. This collection is optional.
The Command object represents a SQL statement or stored procedure that software executes against the datasource. Use of Command objects is optional — data can be extracted directly from a Connection object, if desired.
Command objects may have an associated collection of Parameter objects that provide additional information to the data source when executing the command. The Parameter collection is optional.
Each command execution results in a Recordset containing the results of the query. This object is a mandatory part of ADO.
Each Recordset object is composed of a number of Field objects that represent individual columns in the Recordset. This object is a mandatory feature of ADO.
Each Connection object may have an associated collection of Error objects. ADO utilizes this collection when the connection returns more than one error message at a time. This collection is optional.
The Command object represents a SQL statement or stored procedure that software executes against the datasource. Use of Command objects is optional — data can be extracted directly from a Connection object, if desired.
Command objects may have an associated collection of Parameter objects that provide additional information to the data source when executing the command. The Parameter collection is optional.
Each command execution results in a Recordset containing the results of the query. This object is a mandatory part of ADO.
Each Recordset object is composed of a number of Field objects that represent individual columns in the Recordset. This object is a mandatory feature of ADO.
ADO provides a quick, easy way to access data from a variety of development environments
Set cn = Server.CreateObject(“ADODB.Connection”)
Note that the syntax to create the Connection object will vary from language to language. For example, the equivalent command in Visual Basic would be:
cn = new ADODB.Connection
The basis of all ADO applications is the Connection object. If you’ve properly configured your web server, you can create an instance of this object by simply issuing the VBScript command:
set cn = Server.CreateObject(“ADODB.Connection”)
Setting the Data Source
Once you’ve created the Connection, you need to tell it which data source it should reference through the use of a ConnectionString. In our example, we’re attempting to access a Microsoft SQL Server instance. The ConnectionString contains a list of arguments that define how the data source is accessed. We’ll use the following string:
Once you’ve created the Connection, you need to tell it which data source it should reference through the use of a ConnectionString. In our example, we’re attempting to access a Microsoft SQL Server instance. The ConnectionString contains a list of arguments that define how the data source is accessed. We’ll use the following string:
strCS = “Driver={SQL Server}; Server=myserver; Database=mydb; UID=sa; PWD=password”
The Driver argument tells ADO which type of data source you are accessing. The remainder of the arguments are data source-specific. In this case, you’re specifying the SQL Server instance and default database as well as the user credentials you’d like to present to the server.
Setting the Connection String
Once you’ve built this string, you associate it with the Connection object using the following syntax:
Once you’ve built this string, you associate it with the Connection object using the following syntax:
cn.ConnectionString = strCS
At this point, you’ve provided the Connection object with everything it needs to know to connect to the data source but you haven’t actually connected until you issue the following command:
cn.Open
That’s it! You’ve now successfully opened a connection to a SQL Server database and you’re ready to begin issuing commands and interacting with the server!
No comments:
Post a Comment