473,651 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem filling an ADO recordset from SQL Server

I am having a problem with getting a recordset to fill with data in an
Access Data Project from a SQL Server database.

Here is the code example that is in the Access help files that I can
get to work just fine:

Dim Cnxn As ADODB.Connectio n
Dim rstEmployees As ADODB.Recordset
Dim strCnxn As String
Dim strSQLEmployees As String
Dim varDate As Variant

' Open connection
strCnxn = "Provider='sqlo ledb';Data Source='MySqlSe rver';" & _
"Initial Catalog='Pubs'; Integrated Security='SSPI' ;"
Set Cnxn = New ADODB.Connectio n
Cnxn.Open strCnxn

' Open employee table
Set rstEmployees = New ADODB.Recordset
strSQLEmployees = "employee"
rstEmployees.Op en strSQLEmployees , Cnxn, adOpenKeyset,
adLockOptimisti c, adCmdTable

The only thing I changed was the Data Source from "MySqlServe r" to the
name of our sql server and and this works and pulls in 43 records as
contained in the pubs database example.

So I changed the Inital catalog from "Pubs" to my database on the same
server and changed the table name from "employee" to my table name on
that server and when I run that, it returns back no records when there
is thousands of records in this table. Even thought it returns back no
records, looking at the object in debug mode shows that is knows the
field names of the table so I know that is it connecting correctly to
the database and the table.

My security in sql server is administrator and thus have access to all
database on this server.

Any ideas why I can connect to the text example and return data and not
my production data?

Thanks in advance.....

Nov 13 '05 #1
5 3629
Anyone?

Nov 13 '05 #2
for your code here
' Open connection
strCnxn = "Provider='sqlo ledb';Data Source='MySqlSe rver';" & _
"Initial Catalog='Pubs'; Integrated Security='SSPI' ;"
Set Cnxn = New ADODB.Connectio n
Cnxn.Open strCnxn

' Open employee table
Set rstEmployees = New ADODB.Recordset
strSQLEmployees = "employee"
rstEmployees.Op en strSQLEmployees , Cnxn, adOpenKeyset,
adLockOptimisti c, adCmdTable


try it this way:
--------------------------------------------------
' Open connection
strCnxn = "Provider=SQLOL EDB;Data Source=MySqlSer ver;" & _
"Initial Catalog=Pubs;UI D=SA;PWD=;"
Set Cnxn = New ADODB.Connectio n
Cnxn.Open strCnxn

' Open employee table
Set rstEmployees = New ADODB.Recordset
rstEmployees.Cu rsorLocation = adUseClietn '<--need this
rstEmployees.Op en "Employees" , Cnxn, adOpenDynamic,
adLockPessimist ic, adCmdTable
For i = 1 to 10
Debug.print rstEmployees(0)
Next

------------------------------------

First, I changed your connection string, don't use single quote in the
connection string, plus, you need to specify the UID and PWD as I did
(whatever your UID and PWD are - UID can default to SA, and PWD can be
blank or not PWD=;). Then I specified the cursor location property of
the recordset object. Then I hardcoded your tablename, changed
adOpenKeyset to adOpenDynamic, adLockPessimist ic. I won't promise you
anything because I have also had problems with the ADo recordset object.
I usually read data into a recordset from a stored procedure. Much
faster. Let me know if this works for you.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #4
Rich, Thanks for the reply.

I have this working now. I am currently filling my recordset from a
stored procedure and I have this recordset as the data source for a
form.

Now that I have this working, what I ultimately need to do is before I
fill the from with this data, I need to update one field in all records
of this recordset. This data contains a "from" and a "to" zip code. We
have a mileage application that has API's that we can pass zip codes to
and it will return the driving distance between those two zip codes.
What I need to do is fill the recordset with data from my SP and then go
thru each record in the recordset and extract the "to" and "from" zip
codes, pass it to the API and take the returning distance value and
update the distance field in the recordset. But every attempt to do this
ends up with the error "current recordset does not support updating". I
have tried every possible combination of the objRecordset.Op en command.
Here is the latest one "rstEmployees.O pen strSQLEmployees , Cnxn,
adOpenDynamic, adLockOptimisti c, adCmdStoredProc s"
Any ideas as to how to update a recordset? Is it even possible with a
recordset that is created from a stored procedure? Should I be doing
this a different way? Since this is recordset is not "Connected" to a
table per say, is it possible to update a recordset like this? My
thought that this recordset was like a VB.NET dataset and I could add,
update, and change anything I wanted, but it appears not.
Thanks in advance for any help.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #5
Hello again,

Without seeing what you are doing I can only explain in the blind. So I
will start by synchronizing with your stored procedure. Here is a
typical stored procedure in Sql Server (2000)
-------------------------------------------------
CREATE PROCEDURE [stp_PullZipcode MilageData]

As

Select * From tblZipcodeMilag e --your table in Sql Server

Go
-------------------------------------------------

And here is how you call the SP from an Access Module. First, Make sure
that you have the exact same table in Access, empty of course. The
easiest way to get the exact same table into Access is to export it from
Sql Server using DTS. Actually, this is the easiest way to pass the
data to Access. But I assume you want to automate this since the table
continues to grow. So now you have a table in Sql Server and the Exact
same table in Access. Note: In the Access table you can add one
additional field to the very end of the table where you will eventually
store your Milage data from the 2 zipcodes.

Here is a Sub to populate your Access Table with the Sql Server SP.
Make sure you have a reference to Mdac2.6 in Tools/References (in any
code module in Access). Make sure you have Mdac2.5 and 2.6 loaded on
your calling computer (need Mdac2.5 because it has the Jet interface for
Access - Mdac2.6 does not but has an upgraded ADO interface).

Sup GetZipcodeMilag eData()
Dim cmd As New ADODB.Command, RSado As New ADODB.Recordset
Dim RSdao As DAO.Recordset
Dim i As Integer, j As Integer, RetVal As Variant

DoCmd.SetWarnin gs False
'empty out Access table first
DoCmd.RunSql "Delete * From tblZipCodeMilag e"

cmd.ActiveConne ction = Provider=SQLOLE DB;Data Source=yourServ er;Initial
Catalog=yourSql DB;UID=SA;PWD=; "

cmd.CommandTime out = 60 'One minute - plenty of time for sp

cmd.CommandText = "stp_PullZipcod eMilageData"

Set RSado = cmd.Execute
DoEvents
Do While Not RSado.EOF
RSdao.AddNew
For i = 0 To RSado.Fields.Co unt - 1
RSdao(i) = RSado(i)
Next
RSdao.Update
RSado.MoveNext
j = j + 1
RetVal = SysCmd(acSysCmd SetStatus, j) 'monitor progress
Loop
RSado.Close
RSdao.Close
cmd.ActiveConne ction.Close
End Sub

Now you have your Sql Server Data in Access. So now you can easily
manipulate this data in Access. You could actually do this in Sql
Server with a UDF (user Defined Function) and just pull the results from
the UDF (if you want to go there).

I assume your zipcode API is some custom function written in C. So you
make your API declaration and apply it like this where you supply the
arguments for your API function:

Sub UpdateZipCodeMi lage()
DoCmd.RunSql "Update tblZipcodeMilag e Set Milage =
yourAPIfunction (Zipcode1, Zipcode2)"
End Sub

Depending on how many records you have, say, 50,000, this should take a
few seconds. If you have say 5000 records or less, should take a few
miliseconds.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3306
by: Iain Bishop | last post by:
I'm trying to model objects for the following problem: A building site contains assemblies, each of which can contain other assemblies and/or materials. I have modelled this using a Site class, Assembly class, and Material class as follows... Site Class (clsSite): Option Explicit
9
4330
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side vbscript reads the database and populates a listbox on the page with the first field from each record in the recordset. This works fine. - User selects an option on the listbox and, using the OnChange, I
4
2731
by: Max | last post by:
Hello. This is the first time I've posted to a newsgroup, and I do this because I'm in desperate need of help. I'm working a user management system, and when I activate a user that has registered to my system, the current admin user logged in gets logged out. I can't seem to work out how - I can't even trace back where some of the variables are coming from (for example, the "ref" part of the Request.QueryString method). Could someone...
4
4394
by: JP SIngh | last post by:
Thanks to Manohar for writing the basic code for displaying the managers and the employees in a tree like structure. I have adapted the code below but it gives me an error "exception occcured" after the first recursion. Any ideas what can be done to make the following code work. Thanks
7
1811
by: Munzilla | last post by:
Ok, I have an ASP page that I use to add several pieces of information to a database and also display that information in an edit mode. The problem is, when I use the page for edit, not all of the info is drawn out of the database. Some of the information is drawn out and displayed properly, but other information is not. The strangest part is if I do a response.write to display the objRS() from the database of a field that isn't coming...
3
3722
by: Leo | last post by:
Hi everybody, Is there a way to fill a continuous form with an ADO recordset? Normally when I populate the form with the recordset only the first record is shown. I want to fill all records. Thanks for your help. Leo
1
2942
by: gaucho | last post by:
Hi all, I'm experiencing some problems when filling in bookmarks in word. With my first query (single row returned), no problem at all. Yet, with my new query (which now return 2 rows), i get some error message. --> "Too few parameters, expected 1). I'm having a table which describes what bookmark fits to what field. I query this table to generically fill out my word-document.
22
4313
by: b_r | last post by:
Hi, I'm trying to make a simple operation (insert into DB) in VB 2005 and SQL Server. The code is as follows: Dim sConnectionString As String = _ "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB.mdf....
10
9212
by: shubha.sunkada | last post by:
Hi, I have a recordset connection in asp that I am using to search records.If I use the client side cursorlocation (rs.cursorlocation=3) then it takes really long to return back the records due to which a timeout occurs.If I change the cursorlocation to adUseNone(1) or adUseServer(2) then the search is faster and without any problems.But the sort on records cannot be done if I use adUseClient(3).I need to have sort on these records.
0
8361
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
8278
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8807
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8701
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...
0
8584
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6158
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
5615
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2701
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
1912
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.