Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SqlBulkCopy truncation error message #256

Closed
Suchiman opened this issue Oct 11, 2019 · 3 comments · Fixed by #258
Closed

Improve SqlBulkCopy truncation error message #256

Suchiman opened this issue Oct 11, 2019 · 3 comments · Fixed by #258

Comments

@Suchiman
Copy link
Contributor

Is your feature request related to a problem? Please describe.

When you try to BulkCopy a too large string, you receive following error from here:

System.InvalidOperationException: String or binary data would be truncated.

This message is "faked" by the managed code to look like the message sql server sends.
A year ago, this message is now available in an improved form, at least if the exception is actually thrown by MSSQL.

Describe the solution you'd like

Please make similiar improvements (column and value affected) to the managed exception.

Describe alternatives you've considered

If you can attach a debugger, you can enable first chance exception breaking for InvalidOperationException, then you'll see the string that was too long when you look in the locals window of the throwing stack frame. But this is only applicable when you can debug it.

@Wraith2
Copy link
Contributor

Wraith2 commented Oct 11, 2019

then you'll see the string that was too long when you look in the locals window of the throwing stack

Can you see fhe field definition it was supposed to be put in? and by seeing it do you mean that you as a problem solving human recognise it as invalid or that all the information is present for a dumb computer to report it as you ask? If so it sounds like it would be easy enough to change.

@Suchiman
Copy link
Contributor Author

Yes it seems everything is there, object value contains the string and metadata.column contains the column name. MaxLength is available as metadata.length / 2

@cheenamalhotra
Copy link
Member

Ack: PR #258 to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants