|
|
@@ -43,6 +43,7 @@ using System.ComponentModel;
|
|
|
using System.Data;
|
|
|
using System.Data.Common;
|
|
|
using System.Data.SqlTypes;
|
|
|
+using System.Xml;
|
|
|
|
|
|
namespace System.Data.SqlClient
|
|
|
{
|
|
|
@@ -1104,8 +1105,20 @@ namespace System.Data.SqlClient
|
|
|
{
|
|
|
object value = GetSqlValue (i);
|
|
|
if (!(value is SqlXml)) {
|
|
|
- if (value is DBNull) throw new SqlNullValueException ();
|
|
|
- throw new InvalidCastException ("Type is " + value.GetType ().ToString ());
|
|
|
+ if (value is DBNull) {
|
|
|
+ throw new SqlNullValueException ();
|
|
|
+ } else if (command.Tds.TdsVersion == TdsVersion.tds70 && value is SqlString) {
|
|
|
+ // Workaround for TDS 7 clients
|
|
|
+ // Xml column types are supported only from Sql Server 2005 / TDS 8, however
|
|
|
+ // when a TDS 7 client requests for Xml column data, Sql Server 2005 returns
|
|
|
+ // it as NTEXT
|
|
|
+ MemoryStream stream = null;
|
|
|
+ if (!((SqlString) value).IsNull)
|
|
|
+ stream = new MemoryStream (Encoding.Unicode.GetBytes (value.ToString()));
|
|
|
+ value = new SqlXml (stream);
|
|
|
+ } else {
|
|
|
+ throw new InvalidCastException ("Type is " + value.GetType ().ToString ());
|
|
|
+ }
|
|
|
}
|
|
|
return (SqlXml) value;
|
|
|
}
|