I have a table with a nullable field of type text. When I run an InsertOnSubmit(), it inserts successfully but all formatting is lost. Specifically, I’m storing the stack trace of an error. Each entry has been formatted into its own line and it looks nice, but when I retrieve it from SQL it loses all its crlf4’s.
I have other text fields that seem to retain their formatting, but they were inserted using old ADO.NET. How can this be remedied?
Code:
string[] stacktrace = Environment.StackTrace.Replace('\r', '').Replace('\n', '').Replace(' at', '\n').Split('\n'); string stack = ''; for (int i = 0; i < stacktrace.Length; i++) stack += stacktrace[i].Trim() + '\r\n'; Error err = new Error(); err.Severity = (byte)sev; err.Product = (byte)prod; err.Location = stacktrace[0]; err.Title = message; err.datetime = DateTime.Now; err.StackTrace = stack; dc.Errors.InsertOnSubmit(err); dc.SubmitChanges();
Note that if I debug into the app, err.StackTrace and stack look correct before and after the SubmitChanges().
Error definition:
[Column(Storage='_ID', AutoSync=AutoSync.OnInsert, DbType='Int NOT NULL IDENTITY', IsPrimaryKey=true, IsDbGenerated=true)] public int ID // ... [Column(Storage='_AID', DbType='Int')] public System.Nullable<int> AID // ... [Column(Storage='_Severity', DbType='TinyInt NOT NULL')] public byte Severity [Column(Storage='_Product', DbType='TinyInt NOT NULL')] public byte Product [Column(Storage='_Location', DbType='VarChar(255) NOT NULL', CanBeNull=false)] public string Location [Column(Storage='_Title', DbType='VarChar(255) NOT NULL', CanBeNull=false)] public string Title [Column(Storage='_Ex', DbType='Text', UpdateCheck=UpdateCheck.Never)] public string Ex [Column(Storage='_Notes', DbType='Text', UpdateCheck=UpdateCheck.Never)] public string Notes [Column(Storage='_datetime', DbType='DateTime NOT NULL')] public System.DateTime datetime [Column(Storage='_InnerException', DbType='Text', UpdateCheck=UpdateCheck.Never)] public string InnerException [Column(Storage='_StackTrace', DbType='Text', UpdateCheck=UpdateCheck.Never)] public string StackTrace [Association(Name='Activity_Error', Storage='_Activity', ThisKey='AID', IsForeignKey=true)] public Activity Activity
Did you actually try to look into your SQL database by using the Studio Manager and see what is actually stored in the database. By looking at the data there, you know if there is a problem STORING the data or RETRIEVING the data.
I think the problem lies in the retrieval of the data.