MS Access error "ODBC--call failed. Invalid character value for cast specification (#0)"
Asked Answered
H

7

6

Does anyone have an idea what this error means or how to solve it? I am using Access 2003 and SQL2005. It comes up when trying to add a record on a particular subform.

[Microsoft][SQL Native Client] Invalid character value for cast specification (#0)

This MS bug report describes the same message, but it is a bug in SQL Server 6.5 that has already been solved.

Solved: Apparently having no PK on the destination table was causing this, it didn't have anything to do with the subform or the query from Access. I wasn't even aware there were tables in this database without PK. Adding PK to the destination table solved it. The strange thing is the same query string that errored when executed via SQL native client, executed through SSMS with no errors. Hope this helps anyone else who has come across that strange message.

Hodgkins answered 5/10, 2009 at 23:35 Comment(0)
D
6

Hum, I would check the text box default on the access side. I would also bring up the linked table in design mode, and you want to check the data type that ms-access assumes here. For non supported data types ms-access will generally use a string, and sql server might be wanting something else.

So, check both the Primary key (PK) in main table, and then check the data type used (assumed) in the child table for the foreign key (FK) column. While we are at this, check your expressions used for the child/master link settings in the sub-form control (not the form, not the sub-form, but the sub-form control used in your form that links up these two tables).

Sub forms in access are sensitive if you don’t have a timestamp column in the sql server table. As mentioned check the PK and the FK data types and make sure they match up (just bring up the tables in design mode in ms-access -- you get an error message about the design mode being read only, but just continue on so you can check/view to ensure the data types match up).

So for the child table, you need a PK, a FK, and also a timestamp column (you don’t have to display the TS column in the sub-form, but you need it in the table).

Sub-forms in ms-access are sensitive and often fail if you don’t include a timestamp column in the sql table. (access uses these row version columns to determine if the data been changed).

Damiendamietta answered 6/10, 2009 at 1:41 Comment(2)
You were right.. 2 hours later.. it was because the child table had no PK.. grr!Hodgkins
To second Albert's good answer, let me just say that I've just made it a practice in SQL Server of including a timestamp field in every table as a matter of course -- it just makes things easier. I'd never have a table without a PK in any db engine, so that is not a rule I need to force myself to follow!Recline
E
3

Is one of your fields in the view calculated/built with the CAST function? In this case, you might not have the right to update/add a value for that field.

Can you execute your view in the MS SQL Studio interface and try to insert a record?

Effusive answered 5/10, 2009 at 23:44 Comment(4)
Hi, I don't know what is actually being executed. Inserting a record on the form itself works fine, but trying to insert it when that form is a subform causes this error. The subform just inserts a single text value, no functions, no vba.Hodgkins
in my opinion, the message you get means that the view uses the CAST function somewhere to calculate a value in a field, so the corresponding field cannot be updated. If the problem is specific to the subform, then the link between the form and subform, or the subform recordset's primary key, might be built on this calculated value.Effusive
I am having a look at what is actually happening with the SQL Profiler now, thanks for telling me about it, I can't believe I didn't even know about this before.Hodgkins
Ok, I found the statement that was being executed using SQL Profiler just a normal insert using sp_executesql, pasted it into SSMS and it ran up no problem (1 row(s) affected). Other subforms that have the same kind of insert statement execute fine inside MS Access, so I am just trying to narrow down what the difference is that is causing this one to fail. There is no CAST function anywhere.Hodgkins
A
1

Another cause to this issue is that if you change a table name without alterting the view then the "Dependencies" of that view still remians with the table old name.

Let say I have a table 'A' and a view 'Av' which derives from 'A', and I created a new Table which will be named 'A' and I changed 'A's name to 'A_old' but I didn't executed an ALTER VIEW, so the dependencies of 'Av' still remain on 'A_old' but the view is derives from 'A' and it cuasing this Error in Access when trying to open the view as a linked table

Azoth answered 21/7, 2011 at 8:45 Comment(0)
W
1

I just spent a day battling this with an Access ADP project that was imported into a new Access 2016 ACCDB file. Initially I figured it was an issue with the application code, but I was getting this keying records directly into the table. Interestingly, the records always got written - it seemed to be the read-back that was triggering the error. Profiling the insert sql and running that from SQL Management Studio worked without any issues.

The table that was causing the problems had a GUID Primary Key. Switching that to an int column resolved the issue.

The SQL database was also littered with a few thousand extended properties which I removed before switching the PK. There was a strong suggestion from the web that these cause problems. The source of that process is documented here: Remove All SQL Extended Properties

Winfield answered 6/7, 2016 at 8:38 Comment(0)
A
1

I had this problem with Access 2016 trying to update an ODBC linked sQL Server database. Problem was a null value in field used to join the two tables. Eliminating the null value solved the problem

Advance answered 10/11, 2017 at 22:23 Comment(0)
C
1

OK I just had this bad experience and it had nothing to do with PK or any of this stuff in my situation. The view that reported this problem in Access was created in SQL Server originally and used a CAST of DATETIME to plain old DATE to get rid of the unneeded time part. Up until today this view had caused 0 issues in Access, but started to generate heartburn just as described above.

So, I generated a Drop/Create script for the MSS view, ran it, relinked the views in Access, and the Access database was happy with the result. All my so-called tables in Access are basically views through links to MSS for reporting. I only have 1 table that actually does changes. Other than that, I do not edit through views in Access.

The message is of course useless as usual but this was my solution in my situation.

Culm answered 18/6, 2018 at 20:54 Comment(0)
N
0

Based solely in the message you provided above, it appears that you are trying to set an invalid value to some field or parameter, etc... The message is telling you that it is trying to convert a value into an specific data type but the value is invalid for that data type... makes sense?

Please add more details so we can help you better.

Nature answered 5/10, 2009 at 23:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.