none
Storing unusual characters in database via LINQ DataContext RRS feed

  • Question

  • Hi, I am trying to store text with macrons entered via an ASP.NET web app into a SQL Server database using the LINQ datacontext.

    When I debug my code in VS, I can see that the text is entered OK by querying the textbox text property and also transferred to the LINQ data context data object auto generated from the database table correctly.

    Yet when the dc.myObject.InsertOnSubmit(object) and subsequent dc.SubmitChanges() are executed the text is not stored correctly in the database. The macrons are removed. 

    I know I can store macrons in the database as I can enter text with macrons into the database using Management Studio.

    I'm assuming there's some issue the the Data Context object?

    Any help greatly appreciated

    Regards

    John

    Saturday, February 27, 2016 11:54 PM

Answers

  • Yikers, EBKAC.

    Whilst I had changed the DB field to nvarchar to accept macrons I hadn't updated the dbml file in the application, so the equivalent field in the dbml was still varchar which doesn't handle macrons .....

    My bad, apologies to anyone who spent time on this.

    John

    • Marked as answer by JB_NZ Monday, February 29, 2016 2:35 AM
    Monday, February 29, 2016 2:35 AM

All replies

  • Please post a short, complete repro of the issue.

    David


    David http://blogs.msdn.com/b/dbrowne/

    Sunday, February 28, 2016 12:19 AM
  • Hi David,

    Here's a cut down version of the C# code

        [System.Web.Services.WebMethod(EnableSession = true)]
        public static string CreateKiwiServer(string name)
        {
            try
            {
                using (DataClassesDataContext dc = new DataClassesDataContext())
                {
                    kiwi newKiwi = new kiwi();
                    newKiwi.name = name;
                    dc.kiwis.InsertOnSubmit(newKiwi);
                    dc.SubmitChanges();
                    return newKiwi.kiwi_id.ToString();
                }
            }
            catch (Exception ex)
            {
                return "0";
            }
        }
    

    If I debug this code the string name is passed in with the macron displayed e.g. 'Whā'. The macron is maintained when the string is passed into the property 'newKiwi.name' and retained in the newKiwi object post InsertOnSubmit and SubmitChanges. 

    However in the SQL Server database the macron is not stored. Yet I can use Management Studio to edit the field and update the text to show a macron so the DB can handle macrons. So somewhere between the newKiwi object and the DB the macron is being removed.

    Hope that helps

    John


    Sunday, February 28, 2016 8:07 PM
  • Yikers, EBKAC.

    Whilst I had changed the DB field to nvarchar to accept macrons I hadn't updated the dbml file in the application, so the equivalent field in the dbml was still varchar which doesn't handle macrons .....

    My bad, apologies to anyone who spent time on this.

    John

    • Marked as answer by JB_NZ Monday, February 29, 2016 2:35 AM
    Monday, February 29, 2016 2:35 AM