473,608 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generate Statistics With the OpenSchema Method

ADezii
8,834 Recognized Expert Expert
In last week's Tip, I showed you how to use the ISAMStats Method of the DBEngine (DAO) to return vital statistics concerning Query executions such as: Disk Reads and Writes, Cache Reads and Writes, and Locks placed and released. As promised, in this week's Tip I'll demonstrate how to accomplish parallel functionality within the context of ADO using the OpenSchema Method of the Connection Object.

We indicate to the OpenSchema Method that we would like a Provider-specific set of information by providing it a magic number called a GUID instead of the traditional Constant value indicating a specific Schema. A Recordset is subsequently filled with the information that we need.

Unlike the ISAMStats Method, we can Reset all the statistics at once. Once we've Reset the statistics, we can then execute a Query to refill the statistics and then retrieve them. To do this, we use the OpenSchema Method of the Connection Object, which returns a one-row Recordset Object filled with the statistics in various Fields.

I know you are all anxiously waiting, so let's get to the meat-and-potatoes of this Tip. I've encapsulated all logic in a Sub-Routine Procedure called GetADO_ISAMStat s which has two Arguments. In this specific case, I'll pass to the Routine the name of a Stored Query (qrySelect) and a Boolean Value (True) indicating that the code will attempt to open a Recordset instead of executing a Query. I could very well have passed the Routine an SQL Statement reflecting an Action Query (Update, Delete, Append, Make Table) and then the value False to execute the SQL Statement.

qrySelect is a simple Select Query which returns values from a Table containing 1,101,764 Records. Criteria are set on two Fields just to make things a little interesting.

The Sub-Routine code, the Call to the Routine, and the generated statistics are listed below for your viewing pleasure. See last week's Tip for reference if you so desire.
Expand|Select|Wrap|Line Numbers
  1. Public Sub GetADO_ISAMStats(strQuery As String, Optional blnUseRecordset As Boolean)
  2. '1st set a Reference to the 'Microsoft ActiveX Data Objects X.X Library'
  3. Dim cnn As ADODB.Connection
  4. Dim rst As ADODB.Recordset
  5.  
  6. Set cnn = CurrentProject.Connection
  7.  
  8. Const conDisk_Reads As Integer = 0
  9. Const conDisk_Writes As Integer = 1
  10. Const conReads_From_Cache As Integer = 2
  11. Const conReads_From_Read_Ahead_Cache As Integer = 3
  12. Const conLocks_Placed As Integer = 4
  13. Const conLocks_Released As Integer = 5
  14.  
  15. Dim lngDiskReads As Long, lngDiskWrites As Long, lngReadsFromCache As Long
  16. Dim lngReadsFromReadAheadCache As Long, lngLocksPlaced As Long
  17. Dim lngLocksReleased As Long
  18.  
  19. DoCmd.Hourglass True
  20.  
  21. 'Reset the Statistics all at once
  22. cnn.Properties("Jet OLEDB:Reset ISAM Stats") = 1
  23.  
  24. If blnUseRecordset Then
  25.   Set rst = cnn.Execute(strQuery)     'used for this Tip
  26. Else
  27.   cnn.Execute (strQuery)
  28. End If
  29.  
  30. Set rst = cnn.OpenSchema(Schema:=adSchemaProviderSpecific, SchemaID:="{8703b612-5d43-11d1-bdbf-00c04fb92675}")
  31.  
  32. lngDiskReads = rst.Fields(conDisk_Reads)
  33. lngDiskWrites = rst.Fields(conDisk_Writes)
  34. lngReadsFromCache = rst.Fields(conReads_From_Cache)
  35. lngReadsFromReadAheadCache = rst.Fields(conReads_From_Read_Ahead_Cache)
  36. lngLocksPlaced = rst.Fields(conLocks_Placed)
  37. lngLocksReleased = rst.Fields(conLocks_Released)
  38.  
  39. Debug.Print "==========================================="
  40. Debug.Print "Statistics for (" & strQuery & ") - [" & IIf(blnUseRecordset, "Recordset", "Query") & "]"
  41. Debug.Print "[ADO Method] - Number of Records: " & Format$(DCount("*", "tblMain"), "#,#,#")
  42. Debug.Print "==========================================="
  43. Debug.Print "Disk Reads                     : " & Format$(lngDiskReads, "#,#,#")
  44. Debug.Print "Disk Writes                    : " & Format$(lngDiskWrites, "#,#,#")
  45. Debug.Print "Reads From Cache               : " & Format$(lngReadsFromCache, "#,#,#")
  46. Debug.Print "Reads From Read-Ahead Cache    : " & Format$(lngReadsFromReadAheadCache, "#,#,#")
  47. Debug.Print "Locks Placed                   : " & Format$(lngLocksPlaced, "#,#,#")
  48. Debug.Print "Locks Released                 : " & Format$(lngLocksReleased, "#,#,#")
  49. Debug.Print "==========================================="
  50.  
  51. DoCmd.Hourglass False
  52. End Sub
Expand|Select|Wrap|Line Numbers
  1. 'Procedure Call
  2. Call GetADO_ISAMStats("qrySelect", True)
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. ===========================================
  2. Statistics for (qrySelect) - [Recordset]
  3. [ADO Method] - Number of Records: 1,101,764
  4. ===========================================
  5. Disk Reads                     : 6,970
  6. Disk Writes                    :    22
  7. Reads From Cache               : 7,546
  8. Reads From Read-Ahead Cache    :   968
  9. Locks Placed                   :    31
  10. Locks Released                 :    28
  11. ===========================================
Dec 17 '07 #1
0 5951

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3597
by: Dan | last post by:
Environment: Windows XP Pro, IIS 5, SQL Server 2000 oConnectionString = 'driver={SQL Server};server=(local);uid=sa;pwd=;database=mydatabase;' Relationships are setup on all the tables. EOF is returned for the recordset when using: oRecordSet = oConnection.OpenSchema( adSchemaForeignKeys ) This works when using an Access2000 database, but not for SQL Server 2000.
2
4014
by: Joe User | last post by:
QUESTION for the experts out there :) Is it possible to write a query that would list the datafields by each table in a database? How would I do that?!?! TIA Joe
4
2041
by: Irena | last post by:
Hi all there, I have developed an ASP script that is able to read the structure of an Ms Access database ( via object objConn.OpenSchema(27) ) and to identify the foreign Keys columns and tables (via rstSchema("FK_COLUMN_NAME") and rstSchema("FK_TABLE_NAME")). I wonder whether there is a way to read the displayed field name of the foreign key too.
0
2728
by: Denis ERCHOFF | last post by:
Hi, The OpenSchema method (ADODB._Connection object) seems to work fine in VB but not with C# .... Why? Someone have a solution? My code :
0
1468
by: Marcin Grzêbski | last post by:
Hi All! I can't find any good equivalent of VB6 params from samples which should be used as a 2nd and 3rd parameter in method: Connection.OpenSchema(ADODB.SchemaEnum schema , object criteria , object schemaId); MS .NET wrapper of ADODB force me to declare every parameter
4
4740
by: abcd | last post by:
I have a small VB code which retrives the table names from the access DSN. my code is something like this Set objRs = objConn.OpenSchema(adSchemaTables) If objRs("TABLE_TYPE") = "TABLE" or objRs("TABLE_TYPE") = "TABLE" Then 'do something end if
17
5058
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also identifying memory leaks. The application in question is the Mozilla Web Browser. I also have had similar tasks before in the compiler construction area. And it is easy to come up with many more examples, where such kind of statistics can be very...
4
2425
by: fAnSKyer | last post by:
When using random we can get a uniform data sample. But how to transfer this sample in to a Guassion Sample? Thanks? Did C or C++ provide any function to do this? Thanks a lot. Cheers. fAnS.
30
37040
ADezii
by: ADezii | last post by:
For this Tip, we will show you an extremely handy, multi-user, feature of Jet that allows you to manage Users more effectively. You can create a special, provider-specific Recordset in ADO that supplies information about the current Users in the Database. This is accomplished by using the OpenSchema() Method of the Connection Object, which will fill a recordset with varied sets of different Database Schema information. The output of this...
0
8059
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8470
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6815
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3960
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1328
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.