CommandTimeOut <% Option Explicit Dim conn set conn = server.createobject ("adodb.connection") conn.open "ASPBook", "sa", "yourpassword" Response.Write "The default time out value is: " & Conn.CommandTimeout _ & " seconds.

" conn.CommandTimeout = 60 Response.Write "It has been changed to: " & Conn.CommandTimeout _ & " seconds.

" %> Default DB <% Option Explicit Dim conn set conn = server.createobject ("adodb.connection") conn.open "ASPBook", "sa", "yourpassword" Response.Write "The name of the default database in this SQL Server " _ connection is: " & Conn.DefaultDatabase conn.close conn.open "EmpsDatabase", "Admin", "" Response.Write "

The name of the default database in this Microsoft Access " _ & connection is: " & Conn.DefaultDatabase %> State <% Option Explicit Dim conn set conn = server.createobject ("adodb.connection") Response.Write "The current state of the connection is: " & Conn.State conn.open "ASPBook", "sa", "yourpassword" Response.Write "

The current state of the connection is: " & Conn.State conn.close Response.Write "

The current state of the connection is: " & Conn.State %> Transactions <% Option Explicit Dim conn Dim RS set conn = server.createobject ("adodb.connection") conn.open "AspBook", "sa", "yourpassword" set RS = conn.execute("select * from tblEmps where LastName = 'Doe'" _ & " and FirstName = 'Jane'") If RS.EOF Then Response.Write "

No Jane Doe in the database." Else Response.Write "

Jane Doe was found!" End If conn.close conn.open "AspBook", "sa", "yourpassword" conn.BeginTrans conn.execute "insert into tblEmps (FirstName, LastName) values (" _ & "'Jane', 'Doe')" conn.RollBackTrans set RS = conn.execute("select * from tblEmps where LastName = 'Doe'" _ & " and FirstName = 'Jane'") If RS.EOF Then Response.Write "

No Jane Doe in the database." Else Response.Write "

Jane Doe was found!" End If conn.close conn.open "AspBook", "sa", "yourpassword" conn.BeginTrans conn.execute "insert into tblEmps (FirstName, LastName) values (" _ & "'Jane', 'Doe')" conn.CommitTrans set RS = conn.execute("select * from tblEmps where LastName = 'Doe'" _ & " and FirstName = 'Jane'") If RS.EOF Then Response.Write "

No Jane Doe in the database." Else Response.Write "

Jane Doe was found!" End If %> Execute <% Option Explicit Dim conn Dim RSEmps Dim NumRecordsModified set conn = server.createobject ("adodb.connection") conn.open "AspBook", "sa", "yourpassword" conn.Execute "Update tblEmps set LastName = 'Smith'", NumRecordsModified Response.Write "The update query affected " & NumRecordsModified _ & " records." set RSEmps = conn.execute("Select EmpID, LastName from tblEmps") Do Until RSEmps.EOF Response.Write "

Employee ID: " & RSEmps("EmpID") _ & "
Last Name: " & RSEmps("LastName") RSEmps.MoveNext Loop %> Recordset <% Option Explicit Dim ConnectString Dim CurrentPage Dim RSEmps Dim I If IsEmpty(Request.QueryString("PageNumber")) Then CurrentPage = 1 Else CurrentPage = cint(Request.QueryString("PageNumber")) End If ConnectString = "DSN=EmpsDatabase;User Id=Admin;Password=;" set RSEmps = Server.CreateObject("ADODB.Recordset") RSEmps.CursorLocation = 3 RSEmps.Open "tblEmps", ConnectString, , , 2 RSEmps.PageSize = 3 RSEmps.AbsolutePage = CurrentPage Do Until RSEmps.AbsolutePage <> CurrentPage or RSEmps.EOF Response.Write RSEmps("LastName") & ", " & RSEmps("FirstName") _ & "

" RSEmps.MoveNext Loop Response.Write "Select page to view more employee records: " For I = 1 to RSEmps.PageCount Response.Write "" & I & " " Next %> Empty Recordset <% Option Explicit Dim Conn Dim RSVisitor set conn = server.createobject ("adodb.connection") conn.open "EmpsDatabase", "Admin", "" set RSVisitor = conn.execute("select VisitorID from Visitors where " _ & "UserName = '" & Request.Form("UserName") & "' and " _ & "Password = '" & Request.Form("Password") & "'") If RSVisitor.EOF Then 'Invalid log in Else 'Valid log in End If %> Cache <% Option Explicit Dim ConnectString Dim RSEmps ConnectString = "DSN=EmpsDatabase;User Id=Admin;Password=;" set RSEmps = Server.CreateObject("ADODB.Recordset") Response.Write RSEmps.CacheSize & "

" RSEmps.CacheSize = 5 Response.Write RSEmps.CacheSize %> Sort and Filter <% Option Explicit Dim ConnectString If IsEmpty(Session("RSEmps")) Then ConnectString = "DSN=EmpsDatabase;User Id=Admin;Password=;" set Session("RSEmps") = Server.CreateObject("ADODB.Recordset") Session("RSEmps").CursorLocation = 3 Session("RSEmps").Open "tblEmps", ConnectString, , , 2 Else Session("RSEmps").MoveFirst If Not Isempty(Request.Form("Requery")) Then Session("RSEmps").Sort = Request.Form("SortField") If Request.Form("Filter") = "All" Then Session("RSEmps").Filter = "EmpID > 0" Else Session("RSEmps").Filter = "EmpID = " & Request.Form("Filter") End If End If End If Response.Write "" Response.Write "" Response.Write "" _ & "" Do Until Session("RSEmps").EOF Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Session("RSEmps").MoveNext Loop Response.Write "
Employee IDFirst NameLast Name
" & Session("RSEmps")("EmpID") & "" & Session("RSEmps")("FirstName") & "" & Session("RSEmps")("LastName") & "
" %> Adding a record <% Option Explicit Dim ConnectString ConnectString = "DSN=EmpsDatabase;User Id=Admin;Password=;" set Session("RSEmps") = Server.CreateObject("ADODB.Recordset") Session("RSEmps").CursorType = 1 Session("RSEmps").LockType = 2 Session("RSEmps").Open "tblEmps", ConnectString, , , 2 Session("RSEmps").AddNew Session("RSEmps")("FirstName") = "Lila" Session("RSEmps")("LastName") = "Lopez" Session("RSEmps")("DepartmentID") = 1 Session("RSEmps").Update %> Fields <% Option Explicit Dim ConnectString Dim RSEmps Dim MyField ConnectString = "DSN=EmpsDatabase;User Id=Admin;Password=;" set RSEmps = Server.CreateObject("ADODB.Recordset") RSEmps.CursorLocation = 3 RSEmps.Open "select * from tblEmps where EmpID < 11", ConnectString Response.Write "" Response.Write "" For Each MyField in RSEmps.Fields Response.Write "" Next Response.Write "" Do Until RSEmps.EOF Response.Write "" For Each MyField in RSEmps.Fields Response.Write "" Next Response.Write "" RSEmps.MoveNext Loop Response.Write "
" & MyField.Name & "
" & RSEmps(MyField.Name) & "
" %> Command <% Option Explicit Dim Conn Dim CmdEmps Dim RSEmps set conn = server.createobject ("adodb.connection") conn.open "EmpsDatabase", "Admin", "" Set CmdEmps = Server.CreateObject("ADODB.Command") Set CmdEmps.ActiveConnection = conn CmdEmps.CommandText = "select Count(EmpID) as TheCount from tblEmps " _ & "where DepartmentID = 1" set RSEmps = CmdEMps.Execute Response.Write "Total number of employees in Department 1 is: " _ & RSEmps("TheCount") %> <% Option Explicit Dim conn Dim RSResults set conn = server.createobject ("adodb.connection") conn.open "IISLog", "sa", "yourpassword" conn.commandTimeout = 60 set RSResults = conn.execute ("getStats '" & Request.Form("QueryName") _ & "', '" & Request.Form("UserName") & "', '" & Request.Form("Grouping") & "'") Response.Write RSResults("TotalHits") %> <% Option Explicit Dim Conn Dim Cmd1 Dim RSResults Dim Param1 Dim Param2 Dim Param3 set conn = server.createobject ("adodb.connection") conn.open "IISLog", "sa", "yourpassword" conn.commandTimeout = 60 Set Cmd1= Server.CreateObject("ADODB.Command") Cmd1.CommandText = "getStats" Cmd1.CommandType = 4 Set Param1 = Cmd1.CreateParameter("QueryName", 129, 1) Cmd1.Parameters.Append Param1 Param1.Value = Request.Form("QueryName") Set Param2 = Cmd1.CreateParameter("UserName", 129, 1) Cmd1.Parameters.Append Param2 Param2.Value = Request.Form("UserName") Set Param3 = Cmd1.CreateParameter("Grouping", 3, 1) Cmd1.Parameters.Append Param3 Param3.Value = Request.Form("Grouping") Set Cmd1.ActiveConnection = conn set RSResults = Cmd1.Execute Response.Write RSResults("TotalHits") %> Errors <% Option Explicit On Error Resume Next Dim Conn Dim MyError set conn = server.createobject ("adodb.connection") conn.Open "Garbage" For Each MyError In conn.Errors Response.write "Error Number: " & MyError.Number & "
" Response.write "Description: " & MyError.Description & "
" Response.write "Source: " & MyError.Source & "
" Response.write "State: " & MyError.SQLState & "
" Response.write "Native Error: " & MyError.NativeError & "

" Next %>