RE: Inserted Identity Values in SQL 2005



Hi David,
I just wrote a sample for testing your issue, however since the merge
replication will not be established until tommorrow. I may delay the test
one day and will let you know the result tommorrow.

My test sample code is as following and worked fine at my local computer:
#import "msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
#include <stdio.h>

void execute(LPWSTR strCn,long& nId)
{
CoInitialize(NULL);
try
{
_ConnectionPtr cn(_T("ADODB.Connection"));
_RecordsetPtr rs(_T("ADODB.Recordset"));
_bstr_t strMissing(L"");

cn->Open(strCn,
strMissing, _T(""),
adConnectUnspecified);

rs->Open(_T("INSERT INTO TASK(TASKNAME,TASKDESC)
VALUES('TEST','TEST')"), _variant_t((IDispatch *)cn,true),
adOpenStatic,adLockOptimistic,adCmdText);

rs->Open(_T("SELECT TaskId From Task WHERE TaskId=@@IDENTITY"),
_variant_t((IDispatch *)cn,true), adOpenStatic,adLockOptimistic,adCmdText);
nId = rs->Fields->Item[_T("TaskId")]->Value;

rs->Close();
cn->Close();
}
catch (_com_error &e)
{
nId=-1;
}
::CoUninitialize();
}

Best regards,
Charles Wang
Microsoft Online Community Support
=====================================================
Get notification to my posts through email? Please refer to:
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications

If you are using Outlook Express, please make sure you clear the check box
"Tools/Options/Read: Get 300 headers at a time" to see your reply promptly.


Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
======================================================
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================



.



Relevant Pages

  • Re: C2872 IServiceProvider ambiguous symbol - migrating C++/MFC App with /clr to Visual Studio 2
    ... Infinite thanks for yet another excellent response. ... "typedef interface IServiceProvider IServiceProvider;" ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Intermittent work in UI thread
    ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.vc.mfc)
  • Re: Intermittent work in UI thread
    ... then the issue here is that you would have a timer handler something like ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.vc.mfc)
  • Re: Abort a download
    ... response output finished. ... enough for the raw HTTP communication. ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Inserted Identity Values in SQL 2005
    ... Thanks for your response. ... environment who has a SQL server 2005 merge replication, ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.data.ado)