I'm using ADO.NET to try to get the value I'm about to insert before I insert it in SQL Server 2005. SCOPE_IDENTITY() works fine after, but I'm also inside a transaction if that makes a difference. I literally need to select the next ID, and only the ID and have it available to C# before the insert.
The SCOPE_IDENTITY will only work once you've inserted the row in to the table. If you need to know the value before you insert you will need to use IDENT_CURRENT('table_name'). See http://msdn.microsoft.com/en-us/library/ms175098.aspx for more information.
try using IDENT_CURRENT. As MSDN says, "it returns the last identity value generated for a specific table in any session and any scope"
Whatever solution you choose, make sure to test it under high concurrency. most likely it will break - two or more different connections will get the same ID before they insert. Before doing anything, I would use sp_getapplock to serialize access, so that there is no concurrency.
As an alternative solution you could change your primary key type to a GUID type, this would then allow you to insert with a known key.
Guid pk = Guid.NewGuid();
I dont recall the method for SQL server if the class is directly supported or if you need to convert it to a byte[]. For oracle we convert to a char(32).
This way you dont need to worry about concurrency.