String or Binary DAta would be truncated on Delete - sql-server

I'm trying to delete a couple of rows
USING
SQL Server management studio, for 2 rows only i get the message
No rows were deleted
A problem occurred attempting to delete row #X
Error Source: .Net SqlClient Data Provider
Error Message: String or binary data would be truncated
The Statement has been terminated
Correct the errors and attempt to delete the row again or press ESC to cancel the change(s)
What could be happening while deleting the row ?
the keys are unique so that's not an issue
I've deleted the rows using manual DELETE statements but curious about what's going on here
any thoughts ?
this is using SQL 2008 R2 Express edition
UPDATE - there are no triggers on the table

Try running SQL Profiler while deleting through SSMS if you want to know exactly how it's deleting them.
Do you have a delete trigger on the table? It could be that one of the variables that you're logging into an audit table is longer when going through the GUI instead of through the query window.
In any event, providing the table definition and the rows being deleted might help others find a solution to your question.

Related

#DELETE viewing SQL Server table in Access

A new issue has cropped up this morning. I have databases that reside on SQL Server and I use Access for the front end. One of the databases which has been in use for at least 10 years now suddenly stopped working today, and I have found that the issue is one that is affecting 2 (possible more, I've not checked them all) tables.
When I open the table in access all I get is #DELETED in all the rows and colums. I have seen this behaviour before and it is usually something to do with the data type but this doesn't seem to be the case in this instance.
To troubleshoot the problem I have created a view that retrieves all the columns from the table and when this view is linked and opened in Access I have the same issue. I have found that if I link to the view without selecting a unique record identifier I can see the data without any problem. I could use this as a work-around, but clearly it is not ideal.
The SQL server version is 14.0.2037.2 and I am accessing it using SQL Server Native Client 11.0.
I have found the cause and solution. The affected tables had nvarchar fields as the primary keys. SQL Server Native Client has been deprecated for some time now and is replaced by MS OLE driver which is our mistake. The reason this problem has only reared its head now is due to an update to MS Access 365. I found this which has more details:
#DELETED when linked with ODBC
I had the same issue. This situation emerged this past weekend (5/29/2022).
This is a bug created by a 365 Office update. My update occurred 5/29/2022. The best remedy is to roll back your most-recent 365 update.
In my application, the #Deleted value appeared in all cells linked to any SQL Server table having a nvarchar field included in any unique index - it didn’t have to be a primary key. In my case, eliminating the unique attribute in any index including a nvarchar caused the problem to go away.

Suddenly none of my linked tables work in Access [duplicate]

A new issue has cropped up this morning. I have databases that reside on SQL Server and I use Access for the front end. One of the databases which has been in use for at least 10 years now suddenly stopped working today, and I have found that the issue is one that is affecting 2 (possible more, I've not checked them all) tables.
When I open the table in access all I get is #DELETED in all the rows and colums. I have seen this behaviour before and it is usually something to do with the data type but this doesn't seem to be the case in this instance.
To troubleshoot the problem I have created a view that retrieves all the columns from the table and when this view is linked and opened in Access I have the same issue. I have found that if I link to the view without selecting a unique record identifier I can see the data without any problem. I could use this as a work-around, but clearly it is not ideal.
The SQL server version is 14.0.2037.2 and I am accessing it using SQL Server Native Client 11.0.
I have found the cause and solution. The affected tables had nvarchar fields as the primary keys. SQL Server Native Client has been deprecated for some time now and is replaced by MS OLE driver which is our mistake. The reason this problem has only reared its head now is due to an update to MS Access 365. I found this which has more details:
#DELETED when linked with ODBC
I had the same issue. This situation emerged this past weekend (5/29/2022).
This is a bug created by a 365 Office update. My update occurred 5/29/2022. The best remedy is to roll back your most-recent 365 update.
In my application, the #Deleted value appeared in all cells linked to any SQL Server table having a nvarchar field included in any unique index - it didn’t have to be a primary key. In my case, eliminating the unique attribute in any index including a nvarchar caused the problem to go away.

MS Access linked table to SQL Server update record

I have a table in SQL Server 2012 (Table1) and I have created an MS Access 2016 database and then created a linked table in MS Access to Table1 in SQL Server 2012 using a System DSN.
This works fine, I can open the linked Table1 in MS Access 2016 see the columns and update the values. I have then created a Form in MS Access 2016, added the columns from Table1 to the Form and I can see the data fine.
The problem I have is that the option to Add New Record is greyed out and no matter what I try I cannot add a new record to Table1 using the Form.
If I create a standard (not a linked table) in MS Access 2016 and add the columns to the Form rather than the columns from the Linked Table1 the Add New Record icon is then available.
My question is... Is it possible to use a Form in MS Access 2016, have the data source as a Linked Table to a table in SQL Server 2012 and add new records to it? (And if so, how do I achieve this as I've been at this now for hours and hours and cannot figure it out).
Many thanks in advance.
You note that you can update values when you click on the linked table and view the rows.
Can you ADD rows when using that linked table? And if you cannot, then open up the table using SQL Management Studio and try adding rows that way?
If you don’t have correct (or any) settings in SQL server that sets up or increments the primary key, then you can’t add rows (automatic in this context).
So make sure the table has a primary key, make sure you can add rows using SSMS. If you make changes to fix this SQL table, then you have to re-link the table.
I suggest you create a primary key in the SQL table, and make it a identity column with a increment of 1.
It is certainly possible; this is a very common approach. It sounds like the login you used in the System DSN to connect to SQL Server does not have INSERT permissions on the table. Are you able to review the permissions to check that?
The auto-insertion/update doesn't work for link-database. You need to write a VBA code behind your interface.
Below solution can give you a basic and simple heads up:
Inserting into SQL Server using MS Access
Have a similar situation. Linked Sql Server table, Access Form front end. I am able to insert/update/delete via the form. However, I then created a checkbox to implement a filter on the data. When the box is not checked, I can still edit the data. However, as soon as I check the box to activate the filter, I can no longer insert/update/delete. When I uncheck the box, I can again edit the data. So in my case, the problem is due to the filter, which is implemented via a VBA query involving both an outer join and a union. The query replaces the form's control source when activated, and I believe it is simply too complex for Access to treat it as updatable.

Adding new rows that contain identities, defaults via SQL Server Management Studio GUI

In Enterprise Manager (SQL Server 2000-), you can add new rows to an existing table by right-clicking the table and selecting "Open Table". You get an MS Access-like grid with a single blank row at the bottom for adding new rows.
In Management Studio (SQL Server 2008+), the same functionality is available by right-clicking and selecting "Edit Top 200 Rows".
In the old Enterprise Manager version, any untouched columns are set with either their default value or new identity (if applicable). This happens as soon as focus leaves the row.
In Management studio, any values not explicitly typed-in are set to NULL (even if NULL is not allowed for the column). After focus leaves the row, there is a little exclamation icon to the left of the row with this tooltip:
"This row was successfully committed to the database. However, a problem occurred when attempting to retrieve the data back after the commit. Because of this, the data in this row is read-only. To fix this problem, please re-run the query."
Is there a setting somewhere to enable the old behavior? Or, is there a keyboard shortcut (similar to CTRL+0 == NULL) to indicate you want to use the default?
I feel like I must be missing something obvious--otherwise this view is pretty useless for quickly adding new rows.
I've found that this behavior only happens when SQL Management Studio is connected to a SQL 2000 database. When editing rows on a SQL 2012 database the primary key immediately updates and there is no error icon. I think the best workaround is to just continue to use Enterprise Manager if you need to make quick edits on SQL 2000 databases.
To clear the "to fix this problem please rerun the query" just right click on the read only row with the error and select "! Execute SQL".
the issue is not management studio
this will take place even on a front end application
the issue is having identity column in a table
for some reason this behavior started when SQL 2012 came to life

Message: This row was successfully committed to the database. However, a problem occurred

I have a table in SQL Server 2005 whose primary key is an identity column (increment 1), and I also have a default value set for one of the other columns.
When I open the table in SQL Server Management Studio and type in a new record into the table, the inserted values are not displayed, and I get the following message on save:
However, if the table has either an identity column, or one or more columns with a default value specified, the inserted value(s) will be displayed in the table after a save. And can be edited.
I frequently create test data in ssms this way and this issue makes it cumbersome to do some things I would like to.
Is there any way around this?
Right click on it and say Execute SQL...it should not display it(error)..its just sql server way of doing things..since it inserts the identity column later..You should not add records in that way in the first place.
You should not add records to a database that way! It can have unfortunate side effects (especially on large tables) as you have discovered.
Records for lookup tables should be added through rerunable scripts. Those scripts should in source control. This makes them easy to promote from dev to Qa to staging to prod.
Test records should also be done in scripts (including scripts to remove the test records) so that you can run thenm on other environments as well as being able to delete and recreate them if some process you are testing went bad. These too should eb in source control (as should all database changes which also should not be done through the GUI).

Resources