C# and SQL Server disagree about whether a string is valid Base64 - which is correct?
在SQL Server 2008 R2(SP1)数据库上有下表:
1 2 3 4 | -- irrelevant columns omitted create table Person ( PersonID int, Portrait varchar(max) ) |
1 2 3 | select isnull(cast(N'' as xml).value('xs:base64Binary(sql:column("psn.Portrait"))', 'varbinary(max)'), 0xdeadbeef) as [Portrait] from Person psn with (nolock) where psn.PersonID = <n> |
对于某些行,这将返回有效的
但是,如果我对在SQL Server中返回
1 2 3 4 5 6 7 8 9 | var portraitBytes = Convert.FromBase64String(Sql.SelectSingleString( @"select psn.Portrait from Person psn with (nolock) where psn.PersonID = <n>")); using (var writer = new FileStream(@"C:\portrait.jpg", FileMode.CreateNew)) { writer.Write(portraitBytes, 0, portraitBytes.Length); } |
我能看到的SQL Server视为"有效"的值与那些"无效"的值之间的唯一区别是"无效"的值以字符
如果我在以
所以我的问题是:
经过大量的思考,我发现
在C端,结果发现