MS SQL Server 2014: Error inserting into Temp table with index and identity field

In this thread, I mentioned a problem with SQL Server 2014:
SQL Server 2014: Bug with IDENTITY INSERT ON
The question was answered, it is a bug. To keep you informed on this issue, I open this discussion.
Problem:
The code below works perfectly fine on MS SQL Server 2008 R2 and MS SQL Server 2012, but gives an error every second time the proc is executed on MS SQL Server 2014. If I do not define any index on the temp table, the problem disappears. Defining the index
after the insert, does not help.
SET NOCOUNT ON
GO
IF EXISTS (SELECT 1 FROM sys.procedures WHERE name = 'usp_Test') DROP PROC dbo.usp_Test;
GO
CREATE PROC dbo.usp_Test AS
BEGIN
SET NOCOUNT ON
CREATE TABLE #Source(ID integer NOT NULL);
INSERT INTO #Source VALUES (1), (2), (3);
CREATE TABLE #Dest (ID integer IDENTITY(1,1) NOT NULL);
CREATE INDEX #IDX_Dest ON #Dest (ID);
PRINT 'Check if the insert might cause an identity crisis';
SELECT 'Source' AS SourceTable, * FROM #Source;
SELECT 'Destination' AS DestTable, * FROM #Dest;
SET IDENTITY_INSERT #Dest ON;
PRINT 'Do the insert';
INSERT INTO #Dest (ID) SELECT ID FROM #Source;
PRINT 'Insert ready';
SET IDENTITY_INSERT #Dest OFF;
SELECT * FROM #Dest;
DROP TABLE #Source;
DROP TABLE #Dest;
END;
GO
PRINT 'First execution of the proc, everything OK';
EXEC dbo.usp_Test;
PRINT '';
PRINT 'Second execution of the proc, the insert fails.';
PRINT 'Removing the index #IDX_Dest causes the error to disappear.';
EXEC dbo.usp_Test;
GO
DROP PROC dbo.usp_Test;
GO

There is some progress. Communication from a former Microsoft employee tells us this:
Shivendra Vishal
Engineer at Microsoft
I am no longer with MS, and I do not have code access, however from the public symbols, I could make out following:
sqlmin!SetidentI2I4+0x1f3:
000007fe`f4d865d3 488b10 mov rdx,qword ptr [rax] ds:00000000`00000000=????????????????
ExceptionAddress: 000007fef4d865d3 (sqlmin!SetidentI2I4+0x00000000000001f3)
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 2
Parameter[0]: 0000000000000000
Parameter[1]: 0000000000000000
Attempt to read from address 0000000000000000
This is a read AV and from registers it is clear that we were trying to move the value of location pointed by qword of register rax which is not valid:
rax=0000000000000000 rbx=0000000000000038 rcx=0000000000001030
rdx=0000000000000006 rsi=00000001f55def98 rdi=00000000106fd070
rip=000007fef4d865d3 rsp=00000000106fcf40 rbp=00000000106fcfe9
r8=0000000000000000 r9=00000001f55def60 r10=00000001f55defa0
r11=00000000106fcd20 r12=0000000000000000 r13=0000000000000002
r14=00000001f49c3860 r15=00000001f58c0040
iopl=0 nv up ei pl nz na po nc
cs=0033 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010206
The stack is:
# Child-SP RetAddr Call Site
00 00000000`106fcf40 000007fe`f30c1437 sqlmin!SetidentI2I4+0x1f3
01 00000000`106fd050 000007fe`f474e7ce sqlTsEs!CEsExec::GeneralEval4+0xe7
02 00000000`106fd120 000007fe`f470e6ef sqlmin!CQScanUpdateNew::GetRow+0x43d
03 00000000`106fd1d0 000007fe`f08ff517 sqlmin!CQueryScan::GetRow+0x81
04 00000000`106fd200 000007fe`f091cebe sqllang!CXStmtQuery::ErsqExecuteQuery+0x36d
05 00000000`106fd390 000007fe`f091ccb9 sqllang!CXStmtDML::XretDMLExecute+0x2ee
06 00000000`106fd480 000007fe`f08fa058 sqllang!CXStmtDML::XretExecute+0xad
07 00000000`106fd4b0 000007fe`f08fb66b sqllang!CMsqlExecContext::ExecuteStmts<1,1>+0x427
08 00000000`106fd5f0 000007fe`f08fac2e sqllang!CMsqlExecContext::FExecute+0xa33
09 00000000`106fd7e0 000007fe`f152cfaa sqllang!CSQLSource::Execute+0x86c
0a 00000000`106fd9b0 000007fe`f152c9e8 sqllang!CStmtExecProc::XretLocalExec+0x25a
0b 00000000`106fda30 000007fe`f152a1d8 sqllang!CStmtExecProc::XretExecExecute+0x4e8
0c 00000000`106fe1e0 000007fe`f08fa058 sqllang!CXStmtExecProc::XretExecute+0x38
0d 00000000`106fe220 000007fe`f08fb66b sqllang!CMsqlExecContext::ExecuteStmts<1,1>+0x427
0e 00000000`106fe360 000007fe`f08fac2e sqllang!CMsqlExecContext::FExecute+0xa33
0f 00000000`106fe550 000007fe`f0902267 sqllang!CSQLSource::Execute+0x86c
10 00000000`106fe720 000007fe`f0909087 sqllang!process_request+0xa57
11 00000000`106feee0 000007fe`f2bf49d0 sqllang!process_commands+0x4a3
12 00000000`106ff200 000007fe`f2bf47b4 sqldk!SOS_Task::Param::Execute+0x21e
13 00000000`106ff800 000007fe`f2bf45b6 sqldk!SOS_Scheduler::RunTask+0xa8
14 00000000`106ff870 000007fe`f2c136ff sqldk!SOS_Scheduler::ProcessTasks+0x279
15 00000000`106ff8f0 000007fe`f2c138f0 sqldk!SchedulerManager::WorkerEntryPoint+0x24c
16 00000000`106ff990 000007fe`f2c13246 sqldk!SystemThread::RunWorker+0x8f
17 00000000`106ff9c0 000007fe`f2c13558 sqldk!SystemThreadDispatcher::ProcessWorker+0x3ab
18 00000000`106ffa70 00000000`775d59ed sqldk!SchedulerManager::ThreadEntryPoint+0x226
19 00000000`106ffb10 00000000`7780c541 kernel32!BaseThreadInitThunk+0xd
1a 00000000`106ffb40 00000000`00000000 ntdll!RtlUserThreadStart+0x21
Unassembling the function:
000007fe`f4d8658e 4c8b10 mov r10,qword ptr [rax]
000007fe`f4d86591 4533e4 xor r12d,r12d
000007fe`f4d86594 410fb7d5 movzx edx,r13w
000007fe`f4d86598 4533c9 xor r9d,r9d
000007fe`f4d8659b 4533c0 xor r8d,r8d
000007fe`f4d8659e 488bc8 mov rcx,rax
000007fe`f4d865a1 4489642420 mov dword ptr [rsp+20h],r12d
000007fe`f4d865a6 41ff5230 call qword ptr [r10+30h]
000007fe`f4d865aa 8b5597 mov edx,dword ptr [rbp-69h]
000007fe`f4d865ad 4c8b10 mov r10,qword ptr [rax]
000007fe`f4d865b0 4489642438 mov dword ptr [rsp+38h],r12d
000007fe`f4d865b5 4489642430 mov dword ptr [rsp+30h],r12d
000007fe`f4d865ba 458d442401 lea r8d,[r12+1]
000007fe`f4d865bf 4533c9 xor r9d,r9d
000007fe`f4d865c2 488bc8 mov rcx,rax
000007fe`f4d865c5 c644242801 mov byte ptr [rsp+28h],1
000007fe`f4d865ca 4488642420 mov byte ptr [rsp+20h],r12b
000007fe`f4d865cf 41ff5250 call qword ptr [r10+50h]
000007fe`f4d865d3 488b10 mov rdx,qword ptr [rax] <=================== AV happened over here
000007fe`f4d865d6 488bc8 mov rcx,rax
000007fe`f4d865d9 4c8bf0 mov r14,rax
000007fe`f4d865dc ff5268 call qword ptr [rdx+68h]
000007fe`f4d865df 488d55e7 lea rdx,[rbp-19h]
000007fe`f4d865e3 4c8b00 mov r8,qword ptr [rax]
000007fe`f4d865e6 488bc8 mov rcx,rax
000007fe`f4d865e9 41ff5010 call qword ptr [r8+10h]
000007fe`f4d865ed f6450a04 test byte ptr [rbp+0Ah],4
I remember few issues with scan2ident function, I am not sure if they have fixed it however it appears that this is intoduced to SQL 2014 and we need help from MS to get this resolved as it needs code analysis.
It is not getting simulated for other versions of SQL apart from SQL 2014.
Also to add, interestingly, the value of rax is not visibly changed and it was successfully passed on to rcx, which has a valid value, so something should have changed the value of rax inside call to function using call qword ptr [r10+50h], and looking at this
it appears that it might be a list of functions and we are going at particular offset [50h]. So, bottom line is that the call to function qword ptr [r10+50h], should be changing something in rax, and debugging/analyzing this code might give us some more idea.

Similar Messages

  • Insert into temp table with sorting not works

    Hi,
    Am inserting some of the values into temp table . Before going to insert i will be sorting a cloumn in descending order and then i will try insert. But actually inserts in ascending order.Dont know why.
    Please find the code
    Create table #TempTable( column1 smalldateTime )
    Insert into #TempTable
    Select distinct(column1) from table1 where cloumn2 = 1 order by  column1 desc
    When i query the table
    select * from  #TempTable
    shows the dates are in ascending order instead it should in descending
    But when i query this Select distinct(column1) from table1 where cloumn2 = 1 order by  column1 desc
    dates are in descending order which means recent dates fills top

    Or use a CTE = Common Table Expression:
    CREATE TABLE #test (id int);
    INSERT INTO #test
    SELECT object_id
    FROM sys.objects;
    SELECT COUNT(*)
    FROM #test;
    GO
    ;WITH cte AS
    (SELECT Top 2 *
    FROM #test
    ORDER BY id desc)
    DELETE FROM cte;
    GO
    SELECT COUNT(*)
    FROM #test;
    GO
    DROP TABLE #test;
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Runtime error in Dynamic internal table with AMOUNT and Quantity Fields..

    Dear friends,
    I am attempting write a dymanic Select Statement (with joins).
    And the sleect query looks like this..
      SELECT (LT_SEL_LIST)
      INTO CORRESPONDING FIELDS OF
      TABLE <DYN_TABLE>
      FROM (LT_FROM_LIST)
      WHERE (LT_WHERE3).
    Here the into table is a dynamically created internal table..
    which is created by ...this
    CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG = IT_OUTPUT2[]
        IMPORTING
          EP_TABLE        = DY_TABLE.
    the it_output2 contains the the fieldcatlog information of dynamically given fields :-
    like:-
           TABNAME
           FIELDNAME
           DATATYPE
           LENG
           INTTYPE
           ROLLNAME
           DECIMALS
           REFTABLE
           REFFIELD
    i mean the internal table is constructed with reference to all the bove metadata.
    Problem:- This query run fine with all the fields Except AMOUNT AND QUANTITY fields....
    When the selection list contain VBAK-NETWR or MSEG-MENGE..It throws a runtime error.
    "The data read during a SLECT access couldnt be inserted into the target field,either conversion is not supported for
    the target field's type or the target field is too short."
    after this I even tried to construct the dynamic table with CFILEDNAME and QFIELDNAME in the Fieldcatalog.
    so now my fieldcatlog looks like this:---
    LOOP AT IT_DD03L..
      IF IT_DD03L-DATATYPE = 'CURR'.
           TABLEFIELD-CFIELDNAME = IT_DD03L-FIELDNAME .
           ENDIF.
       IF IT_FIELDCAT3-DATATYPE = 'QUAN'.
           TABLEFIELD-QFIELDNAME = IT_DD03L-FIELDNAME .
      ENDIF.
           TABLEFIELD-TABNAME     = IT_DD03L-TABNAME.
           TABLEFIELD-FIELDNAME   = IT_DD03L-FIELDNAME.
           TABLEFIELD-DATATYPE    = IT_DD03L-DATATYPE.
           TABLEFIELD-INTLEN      = IT_DD03L-LENG.
           TABLEFIELD-INTTYPE     = IT_DD03L-INTTYPE .
           TABLEFIELD-ROLLNAME    = IT_DD03L-ROLLNAME.
           TABLEFIELD-DECIMALS    = IT_DD03L-DECIMALS.
           TABLEFIELD-REF_TABLE   = IT_DD03L-REFTABLE.
           TABLEFIELD-REF_FIELD   = IT_DD03L-REFFIELD.
    APPEND TABLEFIELD.
    CLEAR TABLEFIELD.
    ENDLOOP.
    Note:- this is a test code so ignore performance issues...
    Please help me with some code ...to avoid the Runtime erorr.
    Thanks,
    jeevan.

    Hi Jeevan,
    Why are moving only few fields from DD03L table to your field catalog? Why don't you use move-corresponding? The following code works for me in ECC6.0.
    data: it_dd03l type table of dd03l initial size 0,
          ls_dd03l type dd03l,
          lt_fldcat TYPE lvc_t_fcat,
          ls_fldcat TYPE lvc_s_fcat,
          ls_where(72) TYPE c,
          lt_where LIKE TABLE OF ls_where,
          lt_fld LIKE TABLE OF ls_where,
          lt_data_dy TYPE REF TO data.
    field-symbols: <ft_data> TYPE STANDARD TABLE.
    select * into table it_dd03l from dd03l
        where tabname = 'VBAK'
          and ( fieldname = 'VBELN' or fieldname = 'NETWR' ).
    check sy-subrc eq 0.
    loop at it_dd03l into ls_dd03l.
      move-corresponding ls_dd03l to ls_fldcat.
      append ls_fldcat to lt_fldcat.
      move ls_dd03l-fieldname to ls_where.
      append ls_where to lt_fld.
      if ls_dd03l-fieldname = 'VBELN'.
        clear ls_where.
        concatenate ls_dd03l-fieldname ' <> ''''' into ls_where.
        append ls_where to lt_where.
      endif.
    endloop.
    check not lt_fldcat is initial.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
          EXPORTING
            it_fieldcatalog           = lt_fldcat
          IMPORTING
            ep_table                  = lt_data_dy
          EXCEPTIONS
            generate_subpool_dir_full = 1
            OTHERS                    = 2.
        IF sy-subrc <> 0.
          RAISE no_configuration_data.
        ENDIF.
        ASSIGN lt_data_dy->*  TO <ft_data>.
    check sy-subrc eq 0.
    select (lt_fld) from VBAK into corresponding fields of table
        <ft_data>
        where (lt_where).
    Thanks
    Bala

  • Installation of SCCM 2012 R2 and SQL Server 2014 error

    Hello All,
    I am attempting to setup SQL Server 2014 and SCCM 2012 R2 but I keep running into an error stating that "Configuration Manager requires Microsoft SQL Server
    2008 SP2 w/ CU9........ all the way up to Microsoft SQL Server 2012 with CU2 or higher." I am using all evaluation versions for this configuration as we are looking to test and evaluate the products. I was trying it with SQL 2014 because I was running
    into the same error with SQL 2012 and according to "http://blogs.technet.com/b/configmgrteam/archive/2015/03/30/updated-sc2012-configmgr-sp1-and-sc2012r2-configmgr-support-sql-server-2014.aspx" SQL
    2014 is supported with SCCM 2012 R2. SQL is installed locally on the same box. 
    Any suggestions would be appreciated.
    Thanks,
    Tucker
    Update: When running the Pre-Req check these are some of the failed returns.....
    SQL Server Edition: Failed: Configuration Manager primary site and central administration site don't support SQL Server Express Edition
    Not sure why it is recognizing SQL Express as this is a new machine.
    SQL Server service running account: Failed: The logon account for the SQL Server service cannot be a local user account, NT SERVICE\<sql service name> or LOCAL SERVICE.  You must configure
    the SQL Server service to use a valid domain account, NETWORK SERVICE, or LOCAL SYSTEM.
    For the SQL Service I am using a domain account created specifically for this.

    This has nothing to do with moving or restoring. The kb article says "This hotfix provides updated versions of the setup files and enables new installations
    of the System Center 2012 R2 Configuration Manager site database role and the System Center 2012 Configuration Manager SP1 site database role in Microsoft SQL Server 2014"
    Torsten Meringer | http://www.mssccmfaq.de

  • Sql Server 2014 - Error message: Failed to read BLOB column

    Hi all,
      Am experiencing this error in Microsoft SQL Server 2014 - 12.0.2000.8 (X64) Enterprise Edition (Build 7601: Service Pack 1).
    Error messages:
    Message: Failed to read BLOB column
    Stack:    at Microsoft.SqlServer.Replication.Snapshot.SqlServer.NativeBcpOutProvider.ThrowNativeBcpOutException(CConnection* pNativeConnectionWrapper)
       at Microsoft.SqlServer.Replication.Snapshot.SqlServer.NativeBcpOutProvider.BcpOut(String strBcpObjectName, String strBcpObjectOwner, String strBaseBcpObjectName, Boolean fUnicodeConversion, String strDataFile, String strLoadOrderingHint, String
    strWhereClause, Boolean useTableLockHint, Int32 bcpFileFormatVersion)
       at Microsoft.SqlServer.Replication.Snapshot.SqlServer.BcpOutThreadProvider.DoWork(WorkItem workItem)
       at Microsoft.SqlServer.Replication.WorkerThread.NonExceptionBasedAgentThreadProc()
       at Microsoft.SqlServer.Replication.AgentCore.BaseAgentThread.AgentThreadProcWrapper() (Source: MSSQLServer, Error number: 0)
    Get help: http://help/0
    Message: Shared Memory Provider: No process is on the other end of the pipe.
    Stack:  (Source: MSSQLServer, Error number: 233)
    Get help: http://help/233
    Message: Communication link failure
    Stack:  (Source: MSSQLServer, Error number: 233)
    Get help: http://help/233
    Message: Shared Memory Provider: No process is on the other end of the pipe.
    Stack:  (Source: MSSQLServer, Error number: 233)
    Get help: http://help/233
    Message: Communication link failure
    Stack:  (Source: MSSQLServer, Error number: 233)
    Get help: http://help/233
    Please can you assist me on this issue.

    The error message states a communication link failure has occurred. 
    This is most likely a network related error and usually is transient.
    Try to generate the snapshot again and see if the error still occurs.  If the error still occurs, you will need to have a network admin check the links.
    Brandon Williams (blog |
    linkedin)

  • SQL SERVER 2014 Error :40

    ""A network-related or instance-specification error occured while establishing a connection to SQL Server "" Windows Firewall is on ! what should i do , or change to connect , please help , please 

    QUOTE from an article on the topic: "
    Firstly,
    Make sure your database engine is configured to accept remote connections
    • Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration • Click on Surface Area Configuration for Services and Connections • Select the instance that is having a problem > Database Engine >
    Remote Connections • Enable local and remote connections • Restart instance  - See more at:
    http://www.sswug.org/articlesection/default.aspx?TargetID=44331#sthash.kzSfADZL.dpuf
    Secondly,
    You may need to create an exception on the firewall for the SQL Server instance and port you are using  • Start > Run > Firewall.cpl  • Click on exceptions tab   • Add the sqlservr.exe (typically located in C:\Program Files (x86)\Microsoft
    SQL Server\MSSQL.x\MSSQL\Binn, check your installs for the actual folder path), and port (default is 1433)  • Check your connection string as well - See more at:
    http://www.sswug.org/articlesection/default.aspx?TargetID=44331#sthash.kzSfADZL.dpuf
    Thirdly Check if your SQL server services is up and running properly
    Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> SQL Server Services, and check if SQL Server service status is “Running”.
    In addition, ensure that your remote server is in the same network. Run “sqlcmd -L” in your command prompt to ascertain if your server is included in your network list. You can even find tutorial for the same here SQL SERVER – Find All Servers From Local
    Network – Using sqlcmd – Detect Installed SQL Server on Network.
    Next Enable TCP/IP in SQL Server Configuration
    Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> Select TCP/IP. Right click and select enable
    Lastly Go to your firewall setting, under exception tab, select add port include TCP:1433 and tick the SQL check box."
    LINK:
    http://stackoverflow.com/questions/18060667/connect-to-server-a-network-related-or-instance-specific-error
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • How to insert into a table with a nested table which refer to another table

    Hello everybody,
    As the title of this thread might not be very understandable, I'm going to explain it :
    In a context of a library, I have an object table about Book, and an object table about Subscriber.
    In the table Subscriber, I have a nested table modeling the Loan made by the subscriber.
    And finally, this nested table refers to the Book table.
    Here the code concerning the creation of theses tables :
    Book :
    create or replace type TBook as object
    number int,
    title varchar2(50)
    Loan :
    create or replace type TLoan as object
    book ref TBook,
    loaning_date date
    create or replace type NTLoan as table of TLoan;
    Subscriber :
    create or replace type TSubscriber as object
    sub_id int,
    name varchar2(25)
    loans NTLoan
    Now, my problem is how to insert into a table of TSubscriber... I tried this query, without any success...
    insert into OSubscriber values
    *(1, 'LEVEQUE', NTLoan(*
    select TLoan(ref(b), '10/03/85') from OBook b where b.number = 1)
    Of course, there is an occurrence of book in the table OBook with the number attribute 1.
    Oracle returned me this error :
    SQL error : ORA-00936: missing expression
    00936. 00000 - "missing expression"
    Thank you for your help

    1) NUMBER is a reserved word - you can't use it as identifier:
    SQL> create or replace type TBook as object
      2  (
      3  number int,
      4  title varchar2(50)
      5  );
      6  /
    Warning: Type created with compilation errors.
    SQL> show err
    Errors for TYPE TBOOK:
    LINE/COL ERROR
    0/0      PL/SQL: Compilation unit analysis terminated
    3/1      PLS-00330: invalid use of type name or subtype name2) Subquery must be enclosed in parenthesis:
    SQL> create table OSubscriber of TSubscriber
      2  nested table loans store as loans
      3  /
    Table created.
    SQL> create table OBook of TBook
      2  /
    Table created.
    SQL> insert
      2    into OBook
      3    values(
      4           1,
      5           'No Title'
      6          )
      7  /
    1 row created.
    SQL> commit
      2  /
    Commit complete.
    SQL> insert into OSubscriber
      2    values(
      3           1,
      4           'LEVEQUE',
      5           NTLoan(
      6                  (select TLoan(ref(b),DATE '1985-10-03') from OBook b where b.num = 1)
      7                 )
      8          )
      9  /
    1 row created.
    SQL> select  *
      2    from  OSubscriber
      3  /
        SUB_ID NAME
    LOANS(BOOK, LOANING_DATE)
             1 LEVEQUE
    NTLOAN(TLOAN(000022020863025C8D48614D708DB5CD98524013DC88599E34C3D34E9B9DBA1418E49F1EB2, '03-OCT-85'))
    SQL> SY.

  • Record not inserting into sap table with connector framework ?

    here is the code, but record not being inserting into the table ... but same piece of code working fine while updating ... the record ...
    try {
    interaction = connection.createInteractionEx();
    IInteractionSpec interactionSpec = interaction.getInteractionSpec();
    String functionName = "Z_XYZ";
    interactionSpec.setPropertyValue("Name", functionName);
    String writingTable = "MYTABLE";
    RecordFactory rf = interaction.getRecordFactory();
    MappedRecord importParams = rf.createMappedRecord("input");
    importParams.put("ATTR1", "VALUE1");
    importParams.put("ATTR2", "VALUE2");
    IFunction function = connection.getFunctionsMetaData().getFunction(functionName);
    IStructureFactory sf = interaction.retrieveStructureFactory();
    IRecordSet table = (IRecordSet) sf.getStructure(function.getParameter(writingTable).getStructure());
    table.insertRow();
    table.setString("ATNAME", "VALUE");
    table.setString("ATWRT", "VALUE");
    importParams.put(writingTable, table);
    MappedRecord output = (MappedRecord) interaction.execute(interactionSpec, importParams);
    } catch (Exception e) {
    any idea?
    than ks
    MMK

    Hi Mohan,
    Does a creation through SE37 with the same input work?
    Yoav.

  • Constantly inserting into large table with unique index... Guidance?

    Hello all;
    So here is my world. We have central to our data monitoring system an oracle database running Oracle Standard One (please don't laugh... I understand it is comical) licensing.
    This DB is about 1.7 TB of small record data.
    One table in particular (the raw incoming data, 350gb, 8 billion rows, just in the table) is fed millions of rows each day in real time by two to three main "data collectors" or what have you. Data must be available in this table "as fast as possible" once it is received.
    This table has 6 columns (one varchar usually empty, a few numerics including a source id, a timestamp and a create time).
    The data is collect in chronological order (increasing timestamp) 90% of the time (though sometimes the timestamp may be very old and catch up to current). The other 10% of the time the data can be out of order according to the timestamp.
    This table has two indexes, unique (sourceid, timestamp), and a non unique (create time). (FYI, this used to be an IOT until we had to add the second index on create time, at which point a secondary index on create time slowed the IOT to a crawl)
    About 80% of this data is removed after it ages beyond 3 months; 20% is retained as "special" long term data (customer pays for longer raw source retention). The data is removed using delete statements. This table is never (99.99% of the time) updated. The indexes are not rebuilt... ever... as a rebuild is about a 20+ hour process, and without online rebuilds since we are standard one, this is just not possible.
    Now what we are observing is that the inserts into this table
    - Inserts are much slower based on a "wider" cardinality of the "sourceid" of the data being inserted. What I mean is that 10,000 inserts for 10,000 sourceid (regardless of timestamp) is MUCH, MUCH slower than 10,000 inserts for a single sourceid. This makes sense to me, as I understand it that oracle must inspect more branches of the index for uniqueness, and more different physical blocks will be used to store the new index data. There are about 2 million unique sourceId across our system.
    - Over time, oracle is requesting more and more ram to satisfy these inserts in a timely matter. My understanding here is that oracle is attempting to hold the leafs of these indexes perpetually buffers. Our system does have a 99% cache hit rate. However, we are seeing oracle requiring roughly 10GB extra ram per quarter to 6 months; we're at about 50gb of ram just for oracle already.
    - If I emulate our production load on a brand new, empty table / indexes, performance is easily 10x to 20x faster than what I see when I do the same tests with the large production copies of data.
    We have the following assumption: Partitioning this table based on good logical grouping of sourceid, and then timestamp, will help reduce the work required by oracle to verify uniqueness of data, reducing the amount of data that must be cached by oracle, and allow us to handle our "older than 3 month" at a partition level, greatly reducing table and index fragmentation.
    Based on our hardware, its going to be about a million dollar hit to upgrade to Enterprise (with partitioning), plus a couple hundred thousand a year in support. Currently I think we pay a whopping 5 grand a year in support, if that, total oracle costs. This is going to be a huge pill for our company to swallow.
    What I am looking for guidance / help on, should we really expect partitioning to make a difference here? I want to get that 10x performance difference back we see between a fresh empty system, and our current production system. I also want to limit oracles 10gb / quarter growing need for more buffer cache (the cardinality of sourceid does NOT grow by that much per quarter... maybe 1000s per quarter, out of 2 million).
    Also, please I'd appreciate it if there were no mocking comments about using standard one up to this point :) I know it is risky and insane and maybe more than a bit silly, but we make due with what we have. And all the credit in the world to oracle that their "entry" level system has been able to handle everything we've thrown at it so far! :)
    Alright all, thank you very much for listening, and I look forward to hear the opinions of the experts.

    Hello,
    Here is a link to a blog article that will give you the right questions and answers which apply to your case:
    http://jonathanlewis.wordpress.com/?s=delete+90%25
    As far as you are deleting 80% of your data (old data) based on a timestamp, then don't think at all about using the direct path insert /*+ append */ as suggested by one of the contributors to this thread. The direct path load will not re-use any free space made by the delete. You have two indexes:
    (a) unique index (sourceid, timestamp)
    (b) index(create time)
    Your delete logic (based on arrival time) will smatch your indexes as far as you are always deleting the left hand side of the index; it means you will have what we call a right hand index - In other words, the scattering of the index key per leaf block is certainly catastrophic (there is an oracle iternal function named sys_op_lidbid that will allow you to verify this index information). There is a fairly chance that your two indexes will benefit from a coalesce as already suggested:
               ALTER INDEX indexname COALESCE;This coalesce should be investigated to be done on a regular basis (may be after each 80% delete) You seem to have several sourceid for one timestamp. If the answer is yes you should think about compressing this index
        create index indexname (sourceid, timestamp) compress;     
    or
        alter index indexname rebuild compress;     You will do it only once. Your index will have a smaller size and may be more efficient than it is actually. The index compression will add an extra CPU work during an insert but it might help improving the overal insert process.
    Best Regards
    Mohamed Houri

  • Insert into two tables with a single query (same ID)

    Hello,
    I want to insert two tables at the same time ( with a single query) provided that both records get inserted with the same id. How do I do this?
    Table Movies
    id
    name
    Table Category
    movie_id
    cat_typea) Insert into first table, retrieve the id (may be by using my_sequence.currval and then insert into another table.
    issue: Makes three query to the db, I am also guessing that when multiple people try to insert there will be an issue, I might be wrong.
    I don't have any other idea.
    Greatly appreciated!

    Why don't use multitable insert ? It's available from 9i.
    A sequence.nextval will return the same value within the whole instruction
    so all records can be inserted with the same id.
    Look at this example:
    DROP TABLE A;
    DROP TABLE B;
    drop sequence a_seq;
    CREATE TABLE A(
      ID NUMBER,
      FIRSTNAME VARCHAR2(50)
    CREATE TABLE B AS
    SELECT id, firstname lastname FROM a;
    CREATE SEQUENCE a_seq
    START WITH 1;
    INSERT ALL
    INTO A(ID, FIRSTNAME) VALUES(A_SEQ.NEXTVAL, FNAME)
    INTO B(ID, LASTNAME) VALUES(A_SEQ.NEXTVAL, LNAME)
    SELECT 'fname ' || LEVEL FNAME, 'lname ' || LEVEL LNAME
    FROM DUAL
    CONNECT BY LEVEL < 10
    COMMIT;
    SELECT * FROM A;
    SELECT * FROM b;
    DROP TABLE A succeeded.
    DROP TABLE B succeeded.
    drop sequence a_seq succeeded.
    CREATE TABLE succeeded.
    CREATE TABLE succeeded.
    CREATE SEQUENCE succeeded.
    18 rows inserted
    commited
    ID                     FIRSTNAME                                         
    3                      fname 1                                           
    4                      fname 2                                           
    5                      fname 3                                           
    6                      fname 4                                           
    7                      fname 5                                           
    8                      fname 6                                           
    9                      fname 7                                           
    10                     fname 8                                           
    11                     fname 9                                           
    9 rows selected
    ID                     LASTNAME                                          
    3                      lname 1                                           
    4                      lname 2                                           
    5                      lname 3                                           
    6                      lname 4                                           
    7                      lname 5                                           
    8                      lname 6                                           
    9                      lname 7                                           
    10                     lname 8                                           
    11                     lname 9                                           
    9 rows selected

  • Sporadically getting error "string or binary data would be truncated" in SQL server 2008 while inserting in a Table Type object

    I am facing a strange SQL exception:-
    The code flow is like this:
    .Net 4.0 --> Entity Framework --> SQL 2008 ( StoredProc --> Function {Exception})
    In the SQL Table-Valued Function, I am selecting a column (nvarchar(50)) from an existing table and (after some filtration using inner joins and where clauses) inserting the values in a Table Type Object having a column (nvarchar(50))
    This flow was working fine in SQL 2008 but now all of sudden the Insert into @TableType is throwing  "string or binary data would be truncated"  exception. 
    Insert Into @ObjTableType
    Select * From dbo.Table
    The max length of data in the source column is 24 but even then the insert statement into nvarchar temp column is failing.
    Moreover, the same issue started coming up few weeks back and I was unable to find the root cause, but back then it started working properly after few hours
    (issue reported at 10 AM EST and was automatically resolved post 8 PM EST). No refresh activity was performed on the database.
    This time however the issue is still coming up (even after 2 days) but is not coming up in every scenario. The data set, for which the error is thrown, is valid and every value in the function is fetched from existing tables. 
    Due to its sporadic nature, I am unable to recreate it now :( , but still unable to determine why it started coming up or how can i prevent such things to happen again.
    It is difficult to even explain the weirdness of this bug but any help or guidance in finding the root cause will be very helpful.
    I also Tried by using nvarchar(max) in the table type object but it didn't work.
    Here is a code similar to the function which I am using:
    BEGIN
    TRAN
    DECLARE @PID
    int = 483
    DECLARE @retExcludables
    TABLE
        PID
    int NOT
    NULL,
        ENumber
    nvarchar(50)
    NOT NULL,
        CNumber
    nvarchar(50)
    NOT NULL,
        AId
    uniqueidentifier NOT
    NULL
    declare @PSCount int;
    select @PSCount =
    count('x')
    from tblProjSur ps
    where ps.PID
    = @PID;
    if (@PSCount = 0)
    begin
    return;
    end;
    declare @ExcludableTempValue table (
            PID
    int,
            ENumber
    nvarchar(max),
            CNumber
    nvarchar(max),
            AId
    uniqueidentifier,
            SIds
    int,
            SCSymb
    nvarchar(10),
            SurCSymb
    nvarchar(10)
    with SurCSymbs as (
    select ps.PID,
                   ps.SIds,              
                   csl.CSymb
    from tblProjSur ps
                right
    outer join tblProjSurCSymb pscs
    on pscs.tblProjSurId
    = ps.tblProjSurId
    inner join CSymbLookup csl
    on csl.CSymbId
    = pscs.CSymbId 
    where ps.PID
    = @PID
        AssignedValues
    as (
    select psr.PID,
                   psr.ENumber,
                   psr.CNumber,
                   psmd.MetaDataValue
    as ClaimSymbol,
                   psau.UserId
    as AId,
                   psus.SIds
    from PSRow psr
    inner join PSMetadata psmd
    on psmd.PSRowId
    = psr.SampleRowId
    inner join MetaDataLookup mdl
    on mdl.MetaDataId
    = psmd.MetaDataId
    inner join PSAUser psau
    on psau.PSRowId
    = psr.SampleRowId
                inner
    join PSUserSur psus
    on psus.SampleAssignedUserId
    = psau.ProjectSampleUserId
    where psr.PID
    = @PID
    and mdl.MetaDataCommonName
    = 'CorrectValue'
    and psus.SIds
    in (select
    distinct SIds from SurCSymbs)         
        FullDetails
    as (
    select asurv.PID,
    Convert(NVarchar(50),asurv.ENumber)
    as ENumber,
    Convert(NVarchar(50),asurv.CNumber)
    as CNumber,
                   asurv.AId,
                   asurv.SIds,
                   asurv.CSymb
    as SCSymb,
                   scs.CSymb
    as SurCSymb
    from AssignedValues asurv
    left outer
    join SurCSymbs scs
    on    scs.PID
    = asurv.PID
    and scs.SIds
    = asurv.SIds
    and scs.CSymb
    = asurv.CSymb
    --Error is thrown at this statement
    insert into @ExcludableTempValue
    select *
    from FullDetails;
    with SurHavingSym as (   
    select distinct est.PID,
                            est.ENumber,
                            est.CNumber,
                            est.AId
    from @ExcludableTempValue est
    where est.SurCSymb
    is not
    null
    delete @ExcludableTempValue
    from @ExcludableTempValue est
    inner join SurHavingSym shs
    on    shs.PID
    = est.PID
    and shs.ENumber
    = est.ENumber
    and shs.CNumber
    = est.CNumber
    and shs.AId
    = est.AId;
    insert @retExcludables(PID, ENumber, CNumber, AId)
    select distinct est.PID,
    Convert(nvarchar(50),est.ENumber)
    ENumber,
    Convert(nvarchar(50),est.CNumber)
    CNumber,
                            est.AId      
    from @ExcludableTempValue est 
    RETURN
    ROLLBACK
    TRAN
    I have tried by converting the columns and also validated the input data set for any white spaces or special characters.
    For the same input data, it was working fine till yesterday but suddenly it started throwing the exception.

    Remember, the CTE isn't executing the SQL exactly in the order you read it as a human (don't get too picky about that statement, it's at least partly true enough to say it's partly true), nor are the line numbers or error messages easy to read: a mismatch
    in any of the joins along the way leading up to your insert could be the cause too.  I would suggest posting the table definition/DDL for:
    - PSMetadata, in particular PSRowID, but just post it all
    - tblProjectSur, in particularcolumns CSymbID and TblProjSurSurID
    - cSymbLookup, in particular column CSymbID
    - PSRow, in particular columns SampleRowID, PID,
    - PSAuser and PSUserSur, in particualr all the USERID and RowID columns
    - SurCSymbs, in particular colum SIDs
    Also, a diagnostic query along these lines, repeat for each of your tables, each of the columns used in joins leading up to your insert:
    Select count(asurv.sid) as count all
    , count(case when asurv.sid between 0 and 9999999999 then 1 else null end) as ctIsaNumber
    from SurvCsymb
    The sporadic nature would imply that the optimizer usually chooses one path to the data, but sometimes others, and the fact that it occurs during the insert could be irrelevant, any of the preceding joins could be the cause, not the data targeted to be inserted.

  • How do i insert into temp table

    Hi ALL,
    I have a table APP
    APP_I Acronym Desc
    1 ACC Accounts
    PLTFRM
    swr_pltfrm_i swr_pltfrm_x swr_pltfrm_typ_x
    1 AIX-JAVA Execution
    2 COBOL/BATCH Execution
    3 COBOL/CICS Execution
    4 CONSULTWORKS/MOBILE Delivery
    5 CONSULTWORKS Delivery
    PLTFRM_APP_ENVT
    swr_pltfrm_i app_i
    1 1
    2 1
    3 1
    4 1
    5 1
    I want to create one temporary tab
    TEMP_insert(app_i,desc, acrnymc ,delivery,execution) which have this columns
    App_i desc acrnymc execution
    1 Accounts ACC AIX-JAVA,COBOL/BATCH,COBOL/CICS
    delivery
    CONSULTWORKS,CONSULTWORKS/MOBILE
    How do i insert the row in to the Temp_Insert table based on APP_I as input to my stored procedure.
    Thanks

    hopefully this will help
    dev>declare
      2      cursor c is select empno,ename,job from emp where deptno=20 and rownum<3;
      3      str varchar2(100);
      4  begin
      5      for cur in c loop
      6          str:=str||' '||cur.ename||' '||cur.job;
      7      end loop;
      8      insert into emp_test (ename) VALUES(str);
      9  end; 
    10  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    dev>select ename from emp_test;
    ENAME
    SMITH CLERK JONES MANAGER
    [pre                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Weird problem w. mysql 4.0 when inserting  into a table with auto_incremet

    Since I upgraded my mysql database from 3.23 to 4.0.1
    the following code does not work anymore:
    I get this error msg:
    <b>"Invalid argument value: Duplicate entry '2147483647' for key 1"</b>
    <code>
    package mysql4test;
    import java.sql.*;
    class test {
    public test() {
    public static void main(String[] args) {
    Connection connection = null;
    Statement st = null;
    try {
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    connection = DriverManager.getConnection
    ("jdbc:mysql://192.168.0.4/x?user=x&password=");
    st = connection.createStatement();
    for (int i=1;i<10;i++)
    String insert = "insert into x (b) values('hello');";
    System.out.println(insert);
    st.executeUpdate(insert);
    } catch (Exception ex) { System.err.println(ex.getMessage());}
    </code>
    The table definition of table x is the following:
    create table x(a int(11) primary key auto_increment, b varchar(10));
    What makes the thing even more mysterious is, that doing the same thing as this programm does manually on an mysql client does not produces any error message.
    insert into x (b) values('hello'); works fine on the mysql client deliverd with the server.

    Hi eggsurplus!
    Yes, I succeeded in different ways to solve the problem. changing the table was one of it. but the problem is that i can't simply change all tables (there are a lot) as the are used in other programms.
    The simplest solution that i figured out so far was changing the insert from
    insert into x (b) values('hello')
    to
    insert into x (a,b) values("+i+",'hello')"
    But this solution is still not satisfactory as in more complex programs you can't just use the i variable of the for loop, but you have to add a new variable that increments on every insert.
    This still means changing a lot of code that i wrote for mysql 3.x.
    Besides, i tried also another jdbc driver and it still didn't work.
    The same bug was reported in a PHP forum, but without solution

  • SQL Server 2012 Undetected Deadlock in a table with only one row

      We have migrated our SQL 2000 Enterprise Database to SQL 2012 Enterprise few days ago.
      This is our main database, so most of the applications access it.
      The day after the migration, when users started to run tasks, the database access started to experiment a total failure.
      That is, all processes in the SQL 2k12 database were in lock with each other. This is a commom case of deadlock, but the Database Engine was unable to detect it.
      After some research, we found that the applications were trying to access a very simple table with only one row. This table has a number that is restarted every day and is used to number all the transactions made against the system.   So, client
    applications start a new transaction, get the current number, increment it by one and commit the transaction.
      The only solution we found was to kill all user processes in SQL Server every time this situation occurs (no more than 5 minutes when all clients are accessing the database).
      No client application was changed in this migration and this process was working very well for the last 10 years.
      The problem is that SQL 2k12 is unable to handle this situation compared to SQL 2k.
      It seems to occurs with other tables too, but as this is an "entry table" the problem occurs with it first.
      I have searched internet and some suggest some workarounds like using table hints to completely lock the table at the begining of the transaction, but it can't be used to other tables.
      Does anyone have heard this to be a problem with SQL 2k12? Is there any fixes to make SQL 2k12 as good as SQL 2k?

    First off re: "Unfortunatelly, this can't be used in production environment as exclusive table lock would serialize the accesses to tables and there will be other tables that will suffer with this problem."
    This is incorrect. 
    Using a table to generate sequence numbers like this is a bad idea exactly because the access must be serialized.  Since you can't switch to a SEQUENCE object, which is the correct solution, the _entire goal_ of this exercise to find a way to properly
    serialize access to this table.  Using exclusive locking will not be necessary for all the tables; just for the single-row table used for generating sequence values with a cursor.
    I converted the sample program to VB.NET:
    Public Class Form1
    Private mbCancel As Boolean = False
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim soConn As ADODB.Connection
    Dim soRst As ADODB.Recordset
    Dim sdData As Date
    Dim slValue As Long
    Dim slDelay As Long
    'create database vbtest
    'go
    ' CREATE TABLE [dbo].[ControlNumTest](
    ' [UltData] [datetime] NOT NULL,
    ' [UltNum] [int] NOT NULL,
    ' CONSTRAINT [PK_CorreioNumTeste] PRIMARY KEY CLUSTERED
    ' [UltData] Asc
    ' )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
    ' ) ON [PRIMARY]
    mbCancel = False
    Do
    ' Configure the Connection object
    soConn = New ADODB.Connection
    With soConn
    .ConnectionString = "Provider=SQLNCLI11;Initial Catalog=vbtest;Data Source=localhost;trusted_connection=yes"
    .IsolationLevel = ADODB.IsolationLevelEnum.adXactCursorStability
    .Mode = ADODB.ConnectModeEnum.adModeReadWrite
    .CursorLocation = ADODB.CursorLocationEnum.adUseServer
    .Open()
    End With
    ' Start a new transaction
    Call soConn.BeginTrans()
    ' Configure the RecordSet object
    soRst = New ADODB.Recordset
    With soRst
    .ActiveConnection = soConn
    .CursorLocation = ADODB.CursorLocationEnum.adUseServer
    .CursorType = ADODB.CursorTypeEnum.adOpenForwardOnly
    .LockType = ADODB.LockTypeEnum.adLockPessimistic
    .Open("SELECT * FROM dbo.ControlNumTest")
    End With
    With soRst
    sdData = .Fields!UltData.Value ' Read the last Date (LOCK INFO 1: See comments bello
    slValue = .Fields!UltNum.Value ' Read the last Number
    If sdData <> Date.Now.Date Then ' Date has changed?
    sdData = Date.Now.Date
    slValue = 1 ' Restart number
    End If
    .Fields!UltData.Value = sdData ' Update data
    .Fields!UltNum.Value = slValue + 1 ' Next number
    End With
    Call soRst.Update()
    Call soRst.Close()
    ' Ends the transaction
    Call soConn.CommitTrans()
    Call soConn.Close()
    soRst = Nothing
    soConn = Nothing
    txtUltNum.Text = slValue + 1 ' Display the last number
    Application.DoEvents()
    slDelay = Int(((Rnd * 250) + 100) / 100) * 100
    System.Threading.Thread.Sleep(slDelay)
    Loop While mbCancel = False
    If mbCancel = True Then
    Call MsgBox("The test was canceled")
    End If
    Exit Sub
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    mbCancel = True
    End Sub
    End Class
    And created the table
    CREATE TABLE [dbo].[ControlNumTest](
    [UltData] [datetime] NOT NULL,
    [UltNum] [int] NOT NULL,
    CONSTRAINT [PK_CorreioNumTeste] PRIMARY KEY CLUSTERED
    [UltData] Asc
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = on, FILLFACTOR = 80) ON [PRIMARY]
    ) ON [PRIMARY]
    go insert into ControlNumTest values (cast(getdate()as date),1)
    Then ran 3 copies of the program and generated the deadlock:
    <deadlock>
    <victim-list>
    <victimProcess id="processf27b1498" />
    </victim-list>
    <process-list>
    <process id="processf27b1498" taskpriority="0" logused="0" waitresource="KEY: 35:72057594039042048 (a01df6b954ad)" waittime="1970" ownerId="3181" transactionname="implicit_transaction" lasttranstarted="2014-02-14T15:49:31.263" XDES="0xf04da3a8" lockMode="X" schedulerid="4" kpid="9700" status="suspended" spid="51" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2014-02-14T15:49:31.267" lastbatchcompleted="2014-02-14T15:49:31.267" lastattention="1900-01-01T00:00:00.267" clientapp="vbt" hostname="DBROWNE2" hostpid="21152" loginname="NORTHAMERICA\dbrowne" isolationlevel="read committed (2)" xactid="3181" currentdb="35" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
    <executionStack>
    <frame procname="adhoc" line="1" stmtstart="80" sqlhandle="0x020000008376181f3ad0ea908fe9d8593f2e3ced9882f5c90000000000000000000000000000000000000000">
    UPDATE [dbo].[ControlNumTest] SET [UltData]=@Param000004,[UltNum]=@Param000005 </frame>
    <frame procname="unknown" line="1" sqlhandle="0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000">
    unknown </frame>
    </executionStack>
    <inputbuf>
    (@Param000004 datetime,@Param000005 int)UPDATE [dbo].[ControlNumTest] SET [UltData]=@Param000004,[UltNum]=@Param000005 </inputbuf>
    </process>
    <process id="processf6ac9498" taskpriority="0" logused="10000" waitresource="KEY: 35:72057594039042048 (a01df6b954ad)" waittime="1971" schedulerid="5" kpid="30516" status="suspended" spid="55" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2014-02-14T15:49:31.267" lastbatchcompleted="2014-02-14T15:49:31.267" lastattention="1900-01-01T00:00:00.267" clientapp="vbt" hostname="DBROWNE2" hostpid="27852" loginname="NORTHAMERICA\dbrowne" isolationlevel="read committed (2)" xactid="3182" currentdb="35" lockTimeout="4294967295" clientoption1="671156256" clientoption2="128058">
    <executionStack>
    <frame procname="adhoc" line="1" sqlhandle="0x020000003c6309232ab0edbe0a7790a816a09c4c5ac6f43c0000000000000000000000000000000000000000">
    FETCH API_CURSOR0000000000000001 </frame>
    <frame procname="unknown" line="1" sqlhandle="0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000">
    unknown </frame>
    </executionStack>
    <inputbuf>
    FETCH API_CURSOR0000000000000001 </inputbuf>
    </process>
    </process-list>
    <resource-list>
    <keylock hobtid="72057594039042048" dbid="35" objectname="vbtest.dbo.ControlNumTest" indexname="PK_CorreioNumTeste" id="lockff6e6c80" mode="U" associatedObjectId="72057594039042048">
    <owner-list>
    <owner id="processf6ac9498" mode="S" />
    <owner id="processf6ac9498" mode="U" requestType="wait" />
    </owner-list>
    <waiter-list>
    <waiter id="processf27b1498" mode="X" requestType="convert" />
    </waiter-list>
    </keylock>
    <keylock hobtid="72057594039042048" dbid="35" objectname="vbtest.dbo.ControlNumTest" indexname="PK_CorreioNumTeste" id="lockff6e6c80" mode="U" associatedObjectId="72057594039042048">
    <owner-list>
    <owner id="processf27b1498" mode="U" />
    <owner id="processf27b1498" mode="U" />
    <owner id="processf27b1498" mode="X" requestType="convert" />
    </owner-list>
    <waiter-list>
    <waiter id="processf6ac9498" mode="U" requestType="wait" />
    </waiter-list>
    </keylock>
    </resource-list>
    </deadlock>
    It's the S lock that comes from the cursor read that's the villian here.  U locks are compatible with S locks, so one session gets a U lock and another gets an S lock.  But then the session with an S needs a U, and the session with a U needs an
    X.  Deadlock. 
    I'm not sure what kind of locks were taken by this cursor code on SQL 2000, but on SQL 2012, this code is absolutely broken and should deadlock.
    The right way to fix this code is to add (UPDLOCK,SERIALIZABLE) to the cursor
    .Open("SELECT * FROM dbo.ControlNumTest with (updlock,serializable)")
    So each session reads the table with a restrictive lock, and you don't mix S, U and X locks in this transaction.  This resolves the deadlock, but requires a code change.
    I tried several things that didn't require a code, which did not resolve the deadlock;
    1) setting ALLOW_ROW_LOCKS=OFF ALLOW_PAGE_LOCKS=OFF
    2) SERIALIZABLE isolation level
    3) Switching OleDB providers from SQLOLEDB to SQLNCLI11
    Then I replaced the table with a view containing a lock hint:
    CREATE TABLE [dbo].[ControlNumTest_t](
    [UltData] [datetime] NOT NULL,
    [UltNum] [int] NOT NULL,
    CONSTRAINT [PK_CorreioNumTeste] PRIMARY KEY CLUSTERED
    [UltData] Asc
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = on, FILLFACTOR = 80) ON [PRIMARY]
    ) ON [PRIMARY]
    go
    create view ControlNumTest as
    select * from ControlNumTest_t with (tablockx)
    Which, at least in my limited testing, resovlved the deadlock without any client code change.
    David
    David http://blogs.msdn.com/b/dbrowne/

  • Insert into two tables with trigger on PK in second table

    Hi evereone, ineed help.
    I have two tables (organizations, addresses).
    On addresses table i have trigger on PK. When i do insert i must get this param and insert into OrganizationTable for reference.
    Without ADF i can do insert with returning on addresses, than do insert on organizations with this returning param. How can i do this in ADF business logic using trainTaskFlow?
    Thanks all.
    Edited by: WaterStream on 15.10.2012 15:10

    thanks for reply, but i found solution in this materials:
    http://liuwuhua.blogspot.com/2010/11/master-detail-crud-in-adf-bc.html
    (on this link anyone can download model and see all params)
    but in my project i will get JBO-25030 error.
    Solution founded here:
    http://vtkrishn.com/2011/02/09/oracle-jbo-invalidownerexception/
    Work great!!!

Maybe you are looking for

  • How do I disable Game Center prompts in iOS 8.1?

    Every time I go to open a game, Game centre loads up and it prompts me to sign up for an account.  I don't want one!  Any idea how to disable this? Thanks.

  • HT2506 Mac Preview pdf viewer

    can you please tell me how do I find the file information on a document I have open in preview. I cant work out how to see the path?? and there doesnt seem to be a 'get info' or "show file in finder option"  ? thanks

  • When to enter the Opening Balance.

    Dear All,          I have to enter the Opening Balance today. As of now today's date is 25/09/08. So from which date i should enter the Opening Balance in G/L Accounts, Business Partners and Initial Stock.          Please guide me. Regards Hitesh

  • Looking for a good flash player / plugin

    I have a lot of people asking me to compress there projects to flash lately. I have the flash video 8 encoder and it does a decent job. My work has Sorensen Squeeze but we tend to have it loaded up most of time compressing our own stuff. Does anyone

  • Blank iTunes store page on iPod touch

    I upgraded to iOS 7 on latest generation iPod touch and now I cannot get a picture when I try to access iTune store. Everything else seems to work ok.  Is this something I can fix? Is it problem with new upgrade?