Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9114715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:15:44+00:00 2026-06-17T04:15:44+00:00

I have a piece of code where I add objects and delete another one

  • 0

I have a piece of code where I add objects and delete another one from the object context. When saving changes on the object context, it raises the following SQL Exception:

Failed converting nvarchar value ‘KV Oberaargau136’ to data type int

Of course ‘KV Oberaargau136’ can’t be converted to an int value, the trouble is I don’t know how that string got there. The only place that string can come from is from the following bit of code:

History h = new History()
{
    idTableRef = rpo.idOA,
    tableRef = "RelPersonOrganism",
    date = now,
    idResponsible = entities.getUserOA().id,
    data = "<delete><organism><name><![CDATA[%name%]]></name><id>%id%</id></organism></delete>"
        .Replace("%name%", organism.defaultName)
        .Replace("%id%", organism.idOA.ToString())
};

Where History is an entity and data is a string (actually xml data type on the SQL Server)

So I’ve tried to see with the SQL Profiler what SQL statement could provoke that exception and here is the part of the trace which throws the exception:

RPC:Starting        exec sp_executesql N'insert [dbo].[History]([tableRef], [idTableRef], [date], [idResp...
SQLTransaction
Exception           Error: 245, Severity: 16, State: 1
User Error Message  Conversion failed when converting the nvarchar value 'KV Oberaarau136' to data type int.
SQLTransaction
SP:Completed        insert [dbo].[History]([tableRef], [idTableRef], [date], [idResponsible], [data]) v...
RPC:Completed       exec sp_executesql N'insert [dbo].[History]([tableRef], [idTableRef], [date], [idRespon...

where the complete SQL statement (which shows 3 times in the above trace) is:

EXEC sp_executesql
  N'insert [dbo].[History]([tableRef], [idTableRef], [date], [idResponsible], [data])
values (@0, @1, @2, @3, @4)
select [id]
from [dbo].[History]
where @@ROWCOUNT > 0 and [id] = scope_identity()',
  N'@0 nvarchar(255),@1 int,@2    datetime2(7),@3 int,@4 nvarchar(max) ',
  @0=N'RelPersonOrganism',
  @1=1255,
  @2='2013-01-11     12:35:18.4984109',
  @3=1,
  @4=N'<delete><organism><name><![CDATA[KV Oberaargau]]></name><id>136</id></organism></delete>'

So by looking at the trace, I concluded that this SQL Statement was to be incriminated, although it didn’t seem wrong at all to me. So I tried to execute it in the SQL Server Management Studio and it worked perfectly fine without error…

So what could be triggering that error ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:15:45+00:00Added an answer on June 17, 2026 at 4:15 am

    I can’t see any way the query you posted can cause that error message directly either.

    So check if you have any triggers or computed columns that parse the XML and might be the cause.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code like this: HashSet<Object> Set = new HashSet<Object>(); //add
I have following piece of code: private void nameTextBox_Leave(object sender, EventArgs e) { var
I have this piece of code: public static DateDialogFragment newInstance(Context context, DateDialogFragmentListener listener) {
Say you have the following piece of code: function someProcess() { var deferred =
I have this piece of code that basically checks if one or more files
I have the following piece of code. I would like to know what sort
I have this piece of code : Dictionary<string, object> tempDict = new Dictionary<string, object>();
Let's suppose I have the following code: TEModule teModule = Context.TEModules.Where(module => module.EnumValue.Equals(text.ModuleName)).FirstOrDefault(); if
I have a piece of code from an old project. The logic (in a
I have the following piece of code: DataRow CreateRow(DataTable dt, string name, string country)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.