Convert a username to a SID string in C#/.NET

The podcast tells me I should ask, and answer, questions when they’re not answered on SO already. Here goes. The easy way, with .NET 2.0 and up, is this: NTAccount f = new NTAccount(“username”); SecurityIdentifier s = (SecurityIdentifier) f.Translate(typeof(SecurityIdentifier)); String sidString = s.ToString(); The hard way, which works when that won’t, and works on .NET … Read more

Why does ‘() is ()’ return True when ‘[] is []’ and ‘{} is {}’ return False?

In short: Python internally creates a C list of tuple objects whose first element contains the empty tuple. Every time tuple() or () is used, Python will return the existing object contained in the aforementioned C list and not create a new one. Such mechanism does not exist for dict or list objects which are, … Read more

ADO.NET Entity Framework and identity columns

I know this post is quite old, but this may help the next person arriving hear via a Google search for “Entitiy Framework” and “Identity”. It seems that Entity Frameworks does respect server-generated primary keys, as the case would be if the “Identity” property is set. However, the application side model still requires a primary … Read more

SQL server identity column values start at 0 instead of 1

From DBCC CHECKIDENT DBCC CHECKIDENT ( table_name, RESEED, new_reseed_value ) If no rows have been inserted to the table since it was created, or all rows have been removed by using the TRUNCATE TABLE statement, the first row inserted after you run DBCC CHECKIDENT uses new_reseed_value as the identity. Otherwise, the next row inserted uses … Read more

SQL Server, How to set auto increment after creating a table without data loss?

Changing the IDENTITY property is really a metadata only change. But to update the metadata directly requires starting the instance in single user mode and messing around with some columns in sys.syscolpars and is undocumented/unsupported and not something I would recommend or will give any additional details about. For people coming across this answer on … Read more

Why does the “is” keyword have a different behavior when there is a dot in the string?

is verifies object identity, and any implementation of Python, when it meets literal of immutable types, is perfectly free to either make a new object of that immutable type, or seek through existing objects of that type to see if some of them could be reused (by adding a new reference to the same underlying … Read more

Two variables in Python have same id, but not lists or tuples

Immutable objects don’t have the same id, and as a matter of fact this is not true for any type of objects that you define separately. Generally speaking, every time you define an object in Python, you’ll create a new object with a new identity. However, for the sake of optimization (mostly) there are some … Read more