USER-DEFINED TYPES AND AGGREGATES could result in an invalid representation. For example, look at the following SQL batch that inserts a binary number into an LDimcolumn. Note that binary numbers are implicitly converted to a user-defined type. CREATE TABLE Dims (data LDim) INSERT INTO Dims VALUES (0xBFFFFFFFFFFFFFFE000000000000F03F01) SELECT data FROM Dims 1 in The binary number, 0xBFF … 3F01, is the binary representation of 1in . The very last byte, the 01 on the right, enumerates the units of the dimension. 1 indicates inches, 2 feet, and 3 yards. What happens if that last number is a 4, so that 0xBFFF…3F04 is inserted? Nothing in the representation expects a 4 to be there, and there is no way for the LDim user-defined type to detect that the binary number was inserted. What happened is that a very subtle error was injected into the data, which may be detected at some later time or may just go on to corrupt other data. The SqlUserDefinedTypeAttributehas a property that allows you to specify a method that SQL Server will use to validate an instance of a user- defined type no matter how that value was set. The ValidationMethod Name property takes a string as a parameter and specifies a method in the implementation of the user-defined type that SQL Server can call to validate the binary representation of an instance of the user-defined type. For example, we can extend the implementation of LDimas follows. [Serializable] [SqlUserDefinedType( Format = Format.Native, IsByteOrdered = true, IsFixedLength = true, MaxByteSize = 17, ValidationMethodName= CheckRep )] public struct LDim: INullable, IBinarySerialize { // rest of implementation bool CheckRep() { if(double.IsInfinity(value) || double.IsNaN(value) { return false;

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services

Bookmark the permalink.

Comments are closed.