473,499 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Recordset problem with Access FE and SQL BE

Hello,

I have an application which uses a SQL server 2003 Back end and an
Access 2003 front end.

I am trying to populate a recordset in the FE with data from an ODBC
linked table to the BE. Here is my code:

dim dbs as database, rstList as DAO.RecordSet, sqlString as string
set dbs = currentDB

sqlString = "Select field1, field2 FROM table WHERE field1 = 12345"
set rstList = dbs.openrecordset(sqlString, dbOpenDynaset)

I get an error which says "Runtime Error 4146 - ODBC Call failed". This
works fine if I use an Access BE.

I assume that the problem is to do with the DAO.recordset bit, and that
I'm not connecting correctly to the SQL server BE. Do I need to use a
connection string? Surely I've already connected to SQL when I opened
by application, so I don't understand why it should be a problem. Any
suggestions??

Thanks in advance

Colin

Jan 3 '07 #1
2 2490
Bobby wrote:
Hello,

I have an application which uses a SQL server 2003 Back end and an
Access 2003 front end.

I am trying to populate a recordset in the FE with data from an ODBC
linked table to the BE. Here is my code:

dim dbs as database, rstList as DAO.RecordSet, sqlString as string
set dbs = currentDB

sqlString = "Select field1, field2 FROM table WHERE field1 = 12345"
set rstList = dbs.openrecordset(sqlString, dbOpenDynaset)

I get an error which says "Runtime Error 4146 - ODBC Call failed".
This works fine if I use an Access BE.

I assume that the problem is to do with the DAO.recordset bit, and
that I'm not connecting correctly to the SQL server BE. Do I need to
use a connection string? Surely I've already connected to SQL when I
opened by application, so I don't understand why it should be a
problem. Any suggestions??
Can you open the table link directly?
Can you edit data from the link?
Have you tried dbOpenSnapshot?

If the link works then I see nothing wrong with what you have there providing
the link allows edits. If not, then opening a dynaset type of Recordset might
not be allowed. I use code like that all the time.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Jan 3 '07 #2

Rick Brandt wrote:
>
Can you open the table link directly?
Can you edit data from the link?
Have you tried dbOpenSnapshot?

If the link works then I see nothing wrong with what you have there providing
the link allows edits. If not, then opening a dynaset type of Recordset might
not be allowed. I use code like that all the time.
Thanks again Rick. You have indirectly guided me to the problem. I put
a debug in after the line sqlString = "Select field1, field2 FROM
table WHERE field1 = 12345", and then got the value of sqlString from
the immediate window.

I copied the result into a new query and tried running it. This gave me
the following error:

"[Microsoft][ODBC SQL Server Driver][SQL Server] The text, ntext, and
image data types cannot be compared or sorted except when using IS NULL
or LIKE operator. (#306)"

On investigating, it turns out that field1 is a memo field, so I can't
say "...WHERE field1 = 12345". The following simple change now works:

sqlString = "Select field1, field2 FROM table WHERE field1 like 12345"

Thanks again for your help,

Colin

Jan 3 '07 #3

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

Similar topics

4
5507
by: MNC | last post by:
I'm using Access2002, and can't seem to get an updateable recordset going :-( What am I doing wrong, here's the code. The form's controls are not locked, the recordset type is Dynaset (changing...
22
2837
by: Gerry Abbott | last post by:
Hi all, I having some confusing effects with recordsets in a recent project. I created several recordsets, each set with the same number of records, and related with an index value. I create...
5
7823
by: j.mandala | last post by:
Someone is trying to run my Access 2002 database under Access 2003. He has had a number of problems: 1) i used the MSComCt2.ocx for it's Date and Time picker. I can't find it under 2003. Do I...
3
35417
by: alex_peri | last post by:
Hello All, I am having problems with sorting a recordset by fields in Access. I have a table with three columns called ID, SNo and Time and would like to sort the records by Time. I would like to...
2
8577
by: corepaul | last post by:
I am fairly new to Access and I have a problem trying to use bookmarks with a recordset. I have a recordset dimensioned as, Dim rstFoodDesc As ADODB.Recordset ' recordset Dim bMark As...
0
1627
by: sneal | last post by:
A little background: We have an Access 2002 based user interface to our SQL Server 2000 database. The interface is a tabbed form with two of the tabs containing a subform. Data is pulled from the...
36
4411
by: kjvt | last post by:
Based on a prior posting, I've written a function to convert a recordset to a dataview. The first call to the function for a given recordset works perfectly, but the second call always returns a...
23
52586
by: PW | last post by:
Hi, I'd like to close a recordset and set the database to nothing if a recordset is open if an error has occured. Leaving a recordset open and a database open isn't a good idea, right? ...
0
3112
by: Yarik | last post by:
Hello, Here is a sample (and very simple) code that binds an Access 2003 form to a fabricated ADO recordset: ' Create recordset... Dim rs As ADODB.Recordset: Set rs = New ADODB.Recordset '...
6
5138
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
0
7134
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,...
0
7229
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...
1
6905
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...
0
7395
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...
0
5485
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,...
0
4609
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...
0
3108
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...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
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 ...

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.