does a record string like the following only pull the results from SQL Server

Posted on 2008-11-05
Medium Priority
Last Modified: 2010-03-19
I use Microsoft Access (not a project) as the front end and SQL Server Express 2005 as the data source.  I am trying to speed up my data searches by only retrieiving the filtered information from the SQL Server rather than access pulling all of the data from the table to access and then filtering it.  Am I correct that this code will only pull the correct record from the SQL Server or will it pull the entire table and then filter the record?  Thanks.
Dim cn As ADODB.Connection
   Dim strConnection As String
 strConnection = "ODBC;DSN=qtdsn;TRUSTED_CONNECTION = YES;DATABASE=upsize5sql"
 Set cn = New ADODB.Connection
   With cn
      .Provider = "MSDASQL"
      .Properties("Data Source").Value = strConnection
   End With
   Dim rs As ADODB.Recordset
   Set rs = New ADODB.Recordset
  Set rs = New ADODB.Recordset
   With rs
    Set .ActiveConnection = cn
  .source = "select privacy from tblcustomer where socialsecuritynumber = " & Forms.paymentinputinformation.SSN
    .LockType = adLockOptimistic
    .CursorType = adOpenKeyset
    .CursorLocation = adUseClient
   End With

Open in new window

Question by:garyoallen
LVL 18

Expert Comment

ID: 22887906
That should work but I think that you'll need single quotes around the form field value:

Chr$(39) & Forms.paymentinputinformation.SSN & Chr$(39)
LVL 70

Accepted Solution

Éric Moreau earned 252 total points
ID: 22888119
>>Am I correct that this code will only pull the correct record from the SQL Server or will it pull the entire table and then filter the record?

Yes you are. SQL Server has an engine that is running (normally on a server) that receives the query, parse it, execute it and return only rows that are the result of the request.

When you store an Access database on a server folder, there is no engine on that server that can do that job and that's why the complete table is returned and filtered locally.
LVL 44

Assisted Solution

by:Leigh Purvis
Leigh Purvis earned 248 total points
ID: 22891338
Agreed, as I understand that SSNs, like NI No's, are alphanumeric and hence will be of some Char type which will require quote delimitation.
I should perhaps make clear though that Jet databases (often referred to as an Access database) don't necessarily load an entire table's worth of data to return records (incase that's the impression you take away from this thread).
As emoreau rightly says - the Jet engine doesn't run on the server but on the client.  However that doesn't mean that it has to read entire tables.  A properly indexed table would see such requests reading only the index pages in the MDB file to locate the required record - and the single data page containing that record would then be read (fetched over the wire).
If you're searching on an non-indexed table (tisk tisk) then the engine will have to load the actual pages of record data.  But that would be a practice you'd also want to avoid a server based engine having to perform (the difference/advantage being that it doesn't have to first send the data over the wire as a first step - but it's still making the engine have to work harder - if not the network).
Another point is to do with cursor types.
You've requested a Keyset cursor type - however you've specified a Client side cursor.  The resulting recordset will, in fact, have a Static cursor type rather than Keyset.
ADO replaces types and lock types depending upon what is supported without raising any error.
It should make little to no different to what you subsequently do in this case - but it can play an important role in data requests and is worth bearing in mind for the future.  (i.e. IMO it's always good to request exactly what you'll get).
As a final teeny point, though a definite speed difference isn't always forthcoming - it's more common to use an OLEDB provider with ADO.  Although an ODBC, DSN method as you've used is perfectly viable.
LVL 44

Expert Comment

ID: 22891836
Couldn't have said it better myself;-) - as if!  That post is worth printing and hanging on the wall.

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question