performs the insert since that's where the scope (context) exists. Return
the new identity value as an output parameter. If you call a separate stored
threads at all. Each distinct call to sql server would be a separate scope.
statements is a batch, and would be the scope. If your sql call is executing
a single stored proc, that stored proc would be the scope. Within a stored
<viepia@nospam.com> wrote in message
news:nfnur3t6n19lik9i20fkh1d7vstd57v0ip@4ax.com...
> From
http://msdn2.microsoft.com/en-us/library/ms190315.aspx "A scope is a
> module: a stored
> procedure, trigger, function, or batch. Therefore, two statements are in
> the same scope if
> they are in the same stored procedure, function, or batch." How does
> scope map to
> threads in a C# LINQ application, if it at all?
>
> In running this SPROC:
>
> ALTER PROCEDURE dbo.GetSysIdentity
> @TableName VARCHAR(64),
> @LastIdentity BIGINT OUTPUT
> AS
> BEGIN
> SELECT @LastIdentity = IDENT_CURRENT(@TableName)
> DECLARE @TestIdentiy BIGINT
> SELECT @TestIdentiy = scope_identity()
> IF @TestIdentiy <> @LastIdentity
> RETURN 1
> RETURN 0
> END
>
> so far in my application it as always returned 0.
>
> Iis there an easier way to do this?
>
> System.Reflection.MemberInfo inf = typeof(MyTable);
> object[] attributes = inf.GetCustomAttributes(false);
> System.Data.Linq.Mapping.TableAttribute ta =
> (System.Data.Linq.Mapping.TableAttribute)(attributes[0]);
> long? temp = 0;
> Trace.Assert(db.GetSysIdentity(ta.Name,ref temp) == 0, "Bad
> SPROC");
>
>
> \\ instead of manually typing the table name
> Trace.Assert(db.GetSysIdentity("MyTable",ref temp) == 0, "Bad
> SPROC");
>
>
>
> Thanks very much,
> Viepia
>
>
> On Thu, 21 Feb 2008 20:33:47 -0800, Mufaka <mufaka@mufaka.com> wrote:
>
>>Have you tried scope_identity() instead of @@Identity? IIRC @@Identity
>>doesn't work well if there are triggers or other writes that happen.
>>
>>I think your new SPROC will also suffer from that race condition.
>>
>>I may be a little off point here because I don't know the answer to what
>>you are specifically asking.
>>
>>
>>viepia@nospam.com wrote:
>>> Hi,
>>>
>>> I orignally had a SPROC rerturning @@Identiy, it usually works but
>>> sometimes it
>>> doesn't. In my current project I verified with SQL Server Profiler
>>> that I was reading
>>> @@Identity just after an Insert, but @@Identiy still returned null.
>>>
>>> This SPROC appears to work every time:
>>>
>>> ALTER PROCEDURE dbo.GetSysIdentity
>>> @TableName VARCHAR(64),
>>> @LastIdentity BIGINT OUTPUT
>>> AS
>>> BEGIN
>>> SELECT @LastIdentity = IDENT_CURRENT(@TableName)
>>> RETURN 0
>>> END
>>>
>>> Since I know the name of the SQL Table I am inserting to I can
>>> manually type the name:
>>> long ? lastIdentity = 0;
>>> Trace.Assert(db.GetSysIdentity("MyTable",ref lastIdentity)==0,"Bad
>>> SPROC");
>>>
>>> Is there anywhere in LINQ where I can programmically find the Table
>>> Name? The Table
>>> Name is shown in the <database>DataClasses.dbml diagram in the table's
>>> properties in the
>>> Name and Source fields, how do I access these?
>>>
>>> Thanks
>>> Viepia
>>>
>>>