Real-Time Data Grid Part 1/2 - The GetConnection function
(Page 3 of 5 )
As mentioned on the previous page, the only job of the GetConnection function is to instantiate a new ADO connection object, connect to our SQL Server 2000 database, and if no errors occur, return that ADO connection object. Let's step through the contents of the GetConnection function:
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConnectionStringIt starts by instantiating the ADO connection object into a local variable named objConn. The open method of the ADO connection is called, passing in a variable named strConnectionString. If you look at the top of the dynamic.datagrid.asp class, then you'll see that the strConnectionString variable is defined there. We have defined strConnectionString at the top of dynamic.datagrid.asp so that it is global in a sense. It looks like this (you should change it to match the details of your database server):
strConnectionString = "Provider=SQLOLEDB; Data Source=(local); Initial Catalog=pubs; User Id=sa; Password="In the connection string for our DynamicGrid class, I've set the database name to pubs. You scan change the database name to any database on your server, however I've used pubs because it is a common database available on every SQL server.
Set GetConnection = objConn
If Err.Number = 0 And objConn.Errors.Count = 0 Then
Exit Function
Else
Err.Raise vbObjectError + 1001, "DynamicGrid", "Failed to create ADO Connection object"
End IfNext, we assign our ADO connection object to be returned by the GetConnection function. If any errors occurred either globally, or as part of the connection, then we raise an error using the VBScript Err.Raise method, which would cause our DynamicGrid class to spit an error directly to the browser.
Next: The InitializeGrid routine >>
More ASP Articles
More By Annette Tennison