Quellcode durchsuchen

* SqlDataReader.cs (GetSqlXml): Handle the scenario when Sql Server 2005
returns Xml column type as NTEXT when called from clients that use <
TDS 8.0 protocol.


svn path=/trunk/mcs/; revision=114482

Veerapuram Varadhan vor 17 Jahren
Ursprung
Commit
efe5bd6fb8

+ 6 - 0
mcs/class/System.Data/System.Data.SqlClient/ChangeLog

@@ -1,3 +1,9 @@
+2008-09-30  Veerapuram Varadhan  <[email protected]>
+
+	* SqlDataReader.cs (GetSqlXml): Handle the scenario when Sql
+	Server 2005 returns Xml column type as NTEXT when called from
+	clients that use < TDS 8.0 protocol.
+	
 2008-09-20  Veerapuram Varadhan  <[email protected]>
 
 	* SqlCommand.cs (DeriveParameters): Simplification of the if-else loop.

+ 15 - 2
mcs/class/System.Data/System.Data.SqlClient/SqlDataReader.cs

@@ -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;
 		}