Can T-SQL store ulong's?

13,515

Solution 1

This should answer your question:

http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/ff08c190-a981-4896-9542-3f64b95a84a2/

You would use BigInt, you just have to be careful in how you convert the signed type back into an unsigned type in C#

// This has not been tested
unchecked
{
    myUlong = myDataReader.GetInt64(...);
}

...

The other possibility is to use VarBinary with a length of 8, then convert the bytes to a ulong in C#

Solution 2

I know it's not the same, but would this do:

select convert(decimal(38, 0), 12345678901234567890123456789012345678)

The maximum for an unsigned long seems to be 18,446,744,073,709,551,615 which is significantly less than this decimal can store. There might be issues converting, but I'm sure that a couple of wrapper functions in your application would sort it pretty quickly.

Share:
13,515
Onion-Knight
Author by

Onion-Knight

Work as a Software Developer for a small IT Company.

Updated on June 05, 2022

Comments

  • Onion-Knight
    Onion-Knight almost 2 years

    I want to store a C#.NET ulong into a T-SQL database. I don't see any provisions for doing this, as the SQL bigint has the same Min/Max values as a normal long.

    Is there any way I can do this? Or is catching an OverflowException my only hope?