It actually has absolutely nothing to do with SMO and the database and everything to do with an apparent limitation to the string.Replace()
function. I broke out the LINQ code so that the data was manipulated step by step and found that when I tried to perform the s.Replace("-", "")
, that's where it would error. After digging around on Stack Exchange a little I found: Does string.Replace(string, string) create additional strings? Applying what I found there, I changed the code from using string to using StringBuilder and then used the StringBuilder.Replace(string, string)
function and it works. Apparently because string.Replace(string, string)
creates copies of the source string, there must be some kind of memory limitation, but because StringBuilder operates on the original string instead of copy, that limitation doesn't apply.
In the end the code ends up looking something like:
StringBuilder sb = new StringBuilder(dr["Data"] == DBNull.Value ? "NULL" : BitConverter.ToString((byte[])dr["Data"]));
sb.Replace("-", "");
Thank you for your help on this.