Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 C# long data type best match in sqlserver2005?

Author  Topic 

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2008-01-17 : 14:01:26
Hello,

I am storing a bit mask array (for permissions) in a C# long data type (64 bit), what type should I use in sqlserver? varbinary(64)?

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2008-01-17 : 14:16:26
BIGINT
Go to Top of Page

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2008-01-17 : 14:52:29
Ok i am a bit confused here, how would I represent a 64 bit value in C#?
BIGINT is 8 bytes.

0x000.....0 <--- so how many zeros will there be?
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-01-17 : 15:57:26
sql777 -- please tell me that you know that 8 bits = 1 byte. Right? so 64 bits = 8 bytes.

You should not be messing with bit masks unless you are 100% confident of how they work and how to convert data between bits and bytes and integers and all that, and how to AND and OR and other bitwise operators to mask and retrieve and set bits. If you aren't 100% sure how to do that, you should be simply using multiple bit/boolean columns to store your data. Bitmasking is rarely the way to go since it is not like in the old days when storage space was at a premium. I have not seen a good reason to use a bit mask field in a long time .... (other than maybe for some combinable enums here and there, but that is application, not database code.)

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2008-01-17 : 16:13:26
Jeff, hehe yeah I know I just having touched this stuff in a while (but I have implemented it b4 with AND'ing and OR'ing so I know what i'm doing once I get up to speed again!).

The reason I am using bit masking is because in my web application I need to gather up all the permissions (upto 30-40 for each 'role', and it each user will have multiple roles that I have to combine the permissions for).

That is way to many rows to fetch on a per request basis, so a bit mask will reduce it to maybe 1-4 rows.
Go to Top of Page
   

- Advertisement -