Results 1 to 22 of 22

Thread: Saving StringBuilder To SQL 2008

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Saving StringBuilder To SQL 2008

    I'm scanning a bunch of files and writing the results to a StringBuilder. I then want to save this data to a single column, which I've set as nvarchar(MAX).

    But no matter what I do, it always appears as a blank string in SQL. I wrote the results to a text file as well and everything is there.

    VB.NET Code:
    1. command.Parameters.AddWithValue("@TempFilesLog", TestData.TempFileLog.ToString)

    Any ideas why it isn't working? Should I not save the data this way?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Saving StringBuilder To SQL 2008

    Just to pinpoint the problem a bit - have you tried something like this

    Code:
    command.Parameters.AddWithValue("@TempFilesLog", "abc")
    and seen if it works??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Saving StringBuilder To SQL 2008

    Quote Originally Posted by szlamany View Post
    Just to pinpoint the problem a bit - have you tried something like this

    Code:
    command.Parameters.AddWithValue("@TempFilesLog", "abc")
    and seen if it works??
    Yes and it does.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Saving StringBuilder To SQL 2008

    How about

    Code:
    command.Parameters.AddWithValue("@TempFilesLog", TestData.TempFileLog.ToString.Substring(0,100))
    How long is the TempFileLog string??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Saving StringBuilder To SQL 2008

    Quote Originally Posted by szlamany View Post
    How about

    Code:
    command.Parameters.AddWithValue("@TempFilesLog", TestData.TempFileLog.ToString.Substring(0,100))
    How long is the TempFileLog string??
    I'll try that. It's about 900 lines. But, usually, if the space in the column is not large enough, a very specific error message would appear.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  6. #6

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Saving StringBuilder To SQL 2008

    Quote Originally Posted by szlamany View Post
    How about

    Code:
    command.Parameters.AddWithValue("@TempFilesLog", TestData.TempFileLog.ToString.Substring(0,100))
    How long is the TempFileLog string??
    Hm... well, that worked. But do you know how I can save all of the data?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Saving StringBuilder To SQL 2008

    I ask for length - you give me lines?

    Seems you have non-alpha like characters in this data??

    Try using

    varbinary(max)

    as the datatype instead.

    I store jpg images in sql tables with this datatype...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Saving StringBuilder To SQL 2008

    Don't use addwithvalue - try that next - define you parameter more clearly against the datatype in the DB...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Saving StringBuilder To SQL 2008

    Quote Originally Posted by szlamany View Post
    I ask for length - you give me lines?

    Seems you have non-alpha like characters in this data??

    Try using

    varbinary(max)

    as the datatype instead.

    I store jpg images in sql tables with this datatype...
    I don't know the length without parsing it out. You weren't concerned with the exact length. You were concerned about the length, in terms of it being too large. Telling you it's 900 lines gives you a good idea that it's pretty long.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  10. #10
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Saving StringBuilder To SQL 2008

    Well - 4000 and 8000 are magic numbers in field max sizes in SQL - that's why I was curious...

    Why couldn't you do

    Code:
    debug.writeline TestData.TempFileLog.ToString.Length
    command.Parameters.AddWithValue("@TempFilesLog", TestData.TempFileLog.ToString)

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  11. #11

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Saving StringBuilder To SQL 2008

    Quote Originally Posted by szlamany View Post
    Well - 4000 and 8000 are magic numbers in field max sizes in SQL - that's why I was curious...

    Why couldn't you do

    Code:
    debug.writeline TestData.TempFileLog.ToString.Length
    command.Parameters.AddWithValue("@TempFilesLog", TestData.TempFileLog.ToString)
    It was just an extra step at the time. The length is 823,548. And this is on a low end. The log file could be exponentially larger.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Saving StringBuilder To SQL 2008

    wait... hang on... how are you determining that the field is blank? if you select from the table in SSMS and SEND THE RESULTS TO TEXT... and not grid.... do you then see your results? I've seen cases where a leading crlf shows up in the results... since the result grid doesn't do multiline, it just shows the first result, an empty line... by going into text mode though, you get the results in all its mulit-lined glory goodness.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Saving StringBuilder To SQL 2008

    Quote Originally Posted by techgnome View Post
    wait... hang on... how are you determining that the field is blank? if you select from the table in SSMS and SEND THE RESULTS TO TEXT... and not grid.... do you then see your results? I've seen cases where a leading crlf shows up in the results... since the result grid doesn't do multiline, it just shows the first result, an empty line... by going into text mode though, you get the results in all its mulit-lined glory goodness.

    -tg
    Hm... well... apparently the data is there. If I search for it via a View, it shows as blank data. But if I do a normal query, it shows up.

    View Search:


    Normal Query:


    That seems odd...
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  14. #14
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Saving StringBuilder To SQL 2008

    Show the script that creates the view please...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  15. #15

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Saving StringBuilder To SQL 2008

    So even though the data is saved, it's not all there. It gets truncated.

    Any ideas on the best way to save this data? Could I maybe serialize the physical log file into the database?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  16. #16

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Saving StringBuilder To SQL 2008

    Quote Originally Posted by szlamany View Post
    Show the script that creates the view please...
    SQL Code:
    1. SELECT     TOP (100) PERCENT Date_Test, StopTime, StartTime, Test_Line, Test_Slot, CSO_N, Unit_SN, Family, Bios_Rev, CPU, CPU_TestTime, CPU_HighestTemp, Diags_Ver,
    2.                       Pass_Flag, FailureCD, GoldHDD_Flag, Client_HDDSN, TestStep_Flag, PassMark_TestTime, Bat_1stRead, Bat_2ndRead, ManualPasses, HasBiosUpdated,
    3.                       HasExtendedTest, AdminEID, TempFilesLog, TempFileSizeRaw
    4. FROM         dbo.tbl_TestPassYeild
    5. WHERE     (CSO_N = N'ABC12345')
    6. ORDER BY CSO_N, Date_Test DESC
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  17. #17
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Saving StringBuilder To SQL 2008

    That is interesting... any chance that the view is toasting it? what if you select from the view, join to the table, and pull the field directly from the table rather than through the view? if you get your data then, I'd start researching the view...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  18. #18
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Saving StringBuilder To SQL 2008

    Ummm... no it's not... SSMS has an option to truncate large fields... crap... you're going to make me look it up too aren't you? It's in Options Result Window somewhere... quite often the default is like 800 or so... I tyhink it supports a max of 8120 or something like that... don't know if it's been updated to account for the new varchar(max) option....it's got spinner buttons, set it to some rediculously high number then hit hte up value button and see how far it spins

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  19. #19
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Saving StringBuilder To SQL 2008

    Under query options menu - but I see that is for RESULTS to TEXT. Grid should not have those issues - but I'm not running SSMS 2008...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  20. #20

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Saving StringBuilder To SQL 2008

    Quote Originally Posted by techgnome View Post
    Ummm... no it's not... SSMS has an option to truncate large fields... crap... you're going to make me look it up too aren't you? It's in Options Result Window somewhere... quite often the default is like 800 or so... I tyhink it supports a max of 8120 or something like that... don't know if it's been updated to account for the new varchar(max) option....it's got spinner buttons, set it to some rediculously high number then hit hte up value button and see how far it spins

    -tg
    I set the maximum characters to be displayed, to the max. Which was 8192.

    It shows me more data, but I think I'm missing which property you're referring to. SMSS is definitely truncating the data. Not just the viewable data either. It truncates most of the actual data.

    I exported that record to excel and it only kept about 50 of the 900 lines.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  21. #21
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Saving StringBuilder To SQL 2008

    Select Len(TempFilesLog) From ... will tell you if all the bytes made it into the field.

    And knowing the value it truncated it to would be helpful - if in case it did truncate and we aren't all chasing a red herring...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  22. #22
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Saving StringBuilder To SQL 2008

    honestly, I think it is a herring... and a green one at that... what you REALLY need to do is write some VB code, run the select and see what you get THERE... because in the end, THAT's what's important... not what Query Analyzer/SSMS is returning (which in my opinion is notoriously inaccurate, but with good reason). And DON'T go by the results from the Server Explorer either... I wouldn't trust it either.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width