Setting up distributed transactions between Standard and Express?

  • It appears to have been a query issue. My working theory (so far proved correct) is that the in-memory tables @dtrs and @rawsweep were held only on the originating server. The linked server had to pass back every row to the originating server for criteria selection.

    I created permanent tables archivedtrs and archiverawsweep, in which I populated from memory tables @dtrs and @rawsweep. Then the insert and delete queries work locally against the archive* tables. For the 1 row / 202 rows scenario it ran in 33 seconds.

    Revised query:

    /*

    ONE TIME RUN

    Migrate audit stand 1905 tables tbl_VBSRawSweep and

    tblVBSSweepData from local stand to server.

    Purge copied rows from stand.

    Because the stand RawSweepID was reset to 1, and

    RawSweepID is an identity column in tblVBSSweepData,

    increment the sweep IDs by the maximum current sweep

    ID. Correct data so sweep IDs are sequential with no

    gaps.

    This procedure will run on etswvsvsql003, and accesses

    database [6f_module] on the local stand. The

    stand has already been added to SQL Server's linked

    server list.

    etswvsvexttst\SQLEXPRESS1905

    */

    /*

    3 Sep 2008Loyd Goodbar

    Initial programming.

    Tested against restored copies of databases

    stand_1905_test and server_1905_test

    4 Sep 2008Loyd Goodbar

    Updated script for new columns added per Ken

    Poulard:

    1905:

    tbl_vbsrawsweep

    DateTimedatetime

    SSNnvarchar(50)

    6 Sep 2008Loyd Goodbar

    Change procedure to key off rawsweepid

    from tblvbssweepdata. During extended

    testing, discovered that the rawseepid

    can become "off by 1" if updated

    independently. Only use the tblvbssweepdata's

    rawsweepid.

    10 Sep 2008Loyd Goodbar

    Cleanup and additional testing. Added more

    conditions to copy and delete operations.

    */

    print '----- Script start: ' + convert(char,getdate(),121)

    /* Error variables for catch() block. */

    declare @errmsg nvarchar(4000), @err_severity int

    /*

    In production, set cutoff date to leave 3-5

    minutes of data in table. Hopefully this will not

    copy a partial test sweep. Observed step numbers

    for a test run to 201.

    */

    print '----- Getting cutoff date/time: ' + convert(char,getdate(),121)

    declare @cutoffdatetime as datetime

    set @cutoffdatetime = dateadd(mi,-5,getdate())

    select convert(char,@cutoffdatetime,21)

    /*

    Track maximum sweep ID from tables to convert incoming

    sweep ID from 1905 to (maximum sweep ID + 1) on SQL003.

    */

    print '----- Getting last data sweep raw id: ' + convert(char,getdate(),121)

    declare @lastdatasweepid int

    select @lastdatasweepid = max(rawsweepid)

    from [etswvsvsql003].[server_1905_test].[dbo].[tblvbssweepdata]

    select @lastdatasweepid as [last data sweep id] --, @lastrawsweepid as [last raw sweep id] -- verification

    /*

    Table tblVBSSweepData contains a date time and sweep ID.

    Generate table with date time values in order to provide

    clean cutoff. Generate table of raw sweep ID, test ID,

    solenoid ID, and step number based on first table, to

    narrow selection in tbl_VBSRawSweep.

    Gather keys for data to be archived and purged.

    Observed keys:

    tblVBSSweepData

    DateTime

    RawSweepID

    tbl_VBSRawSweep

    RawSweepID

    TestID

    SolID

    StepNumber

    */

    print '----- Populate virtual table @dtrs: ' + convert(char,getdate(),121)

    declare @dtrs table (dt datetime, rs int, tst int, sol int, crs2 int null)

    insert into @dtrs (dt, rs, tst, sol)

    select top 1 datetime, rawsweepid, testid, solid

    from [etswvsvexttst\SQLEXPRESS].[6f_module].[dbo].[tblvbssweepdata]

    where datetime < @cutoffdatetime

    print '----- Populate virtual table @rawsweep: ' + convert(char,getdate(),121)

    declare @rawsweep table

    (rs int, tst int, sol int, step int, crs2 int null)

    insert into @rawsweep (rs, tst, sol, step)

    select rawsweepid, testid, solid, stepnumber

    from [etswvsvexttst\SQLEXPRESS].[6f_module].[dbo].[tbl_vbsrawsweep] a

    join @dtrs b on (a.rawsweepid = b.rs)

    /*

    We need to convert the incoming sweep IDs to follow the

    existing IDs in SQL003 tables. Logic to convert the ID

    without leaving gaps:

    "maximum sweep ID from SQL003" - "minimum sweep ID from 1905" +

    "current sweep ID value" + 1

    Ex.

    "maximum sweep ID from SQL003"106328-

    "minimum sweep ID from 1905"78+

    "current sweep ID value"78+

    1=106329

    Ex.

    "maximum sweep ID from SQL003"106328-

    "minimum sweep ID from 1905"78+

    "current sweep ID value"350+

    1=106601

    */

    declare @mindtrssweep int

    select @mindtrssweep = min(rs) from @dtrs

    print '----- Update virtual tables with corrected raw sweep value: ' + convert(char,getdate(),121)

    update @dtrs set crs2 = @lastdatasweepid - @mindtrssweep + rs + 1

    update @rawsweep set crs2 = @lastdatasweepid - @mindtrssweep + rs + 1

    print '----- Show what will be copied: ' + convert(char,getdate(),121)

    select * from @dtrs order by 1,2 -- verification

    select * from @rawsweep order by 1,2,3,4 -- verification

    /*

    Now variable tables @dtrs and @rawsweep contain

    the data required for row copy and purge.

    */

    print '----- Starting transaction: ' + convert(char,getdate(),121)

    set xact_abort on -- Required by OLE DB to ignore "nested transaction" errors. See http://msdn.microsoft.com/en-us/library/ms188792.aspx

    begin try

    begin distributed transaction

    /*

    Table requirements on linked server:

    archivedtrs, archiverawsweep

    */

    print char(13) + '----- Purge 6f_module temp table archivedtrs: ' + convert(char,getdate(),121)

    delete from [etswvsvexttst\sqlexpress].[6f_module].[dbo].[archivedtrs]

    print char(13) + '----- Send @dtrs to linked server, archivedtrs: ' + convert(char,getdate(),121)

    insert into [etswvsvexttst\sqlexpress].[6f_module].[dbo].[archivedtrs]

    (dt, rs, tst, sol, crs2)

    select dt, rs, tst, sol, crs2 from @dtrs

    print char(13) + '----- Purge 6f_module temp table archiverawsweep: ' + convert(char,getdate(),121)

    delete from [etswvsvexttst\sqlexpress].[6f_module].[dbo].[archiverawsweep]

    print char(13) + '----- Send @dtrs to linked server, archiverawsweep: ' + convert(char,getdate(),121)

    insert into [etswvsvexttst\sqlexpress].[6f_module].[dbo].[archiverawsweep]

    (rs, tst, sol, step, crs2)

    select rs, tst, sol, step, crs2 from @rawsweep

    /* - - - - - - - - - - */

    print char(13) + '----- Insert from 6f_module to server_1905_test, tblvbssweepdata: ' + convert(char,getdate(),121)

    set identity_insert [server_1905_test].[dbo].[tblvbssweepdata] on

    insert into [etswvsvsql003].[server_1905_test].[dbo].[tblvbssweepdata]

    (TestID, SolID, RawSweepID, ModuleSN, SSN, Passed, [DateTime],

    [Type], [Description], Operator, Comments, SolenoidType,

    SweepTable, Kp, Ki, AdlerPeriod, StepsinWave,

    SwitchingFrequency, DitherFrequency, PurgeTime, SweepTime,

    FluidTemperature, AverageSupply, SupplyMinimum, SupplyMinimumat,

    SupplyMaximum, SupplyMaximumat, SupplyRange, Flowat0, Flowat850,

    MaximumFlow, MaximumFlowat, MaximumRippleinc, MaximumRippleincat,

    MaximumRippledec, MaximumRippledecat, MaximumGain, MaximumGainat,

    MaximumHysteresis, MaximumHysteresisat, RepeatAvgHysterisis,

    GatePoint1lowcurrent, GatePoint1lowpressure, GatePoint1highcurrent,

    GatePoint1highpressure, GatePoint2lowcurrent, GatePoint2lowpressure,

    GatePoint2highcurrent, GatePoint2highpressure, MinimumPressure,

    RawDataFileName, Step1Pressureinc, Step2Pressureinc, Step3Pressureinc,

    Step4Pressureinc, Step5Pressureinc, Step6Pressureinc, Step7Pressureinc,

    Step8Pressureinc, Step9Pressureinc, Step10Pressureinc,

    Step1PressureAverage, Step2PressureAverage, Step3PressureAverage,

    Step4PressureAverage, Step5PressureAverage, Step6PressureAverage,

    Step7PressureAverage, Step8PressureAverage, Step9PressureAverage,

    Step10PressureAverage, RecheckPressure1, RecheckPressure2,

    RecheckPressure3, RecheckPressure4, RecheckPressure5,

    RecheckPressure6, RecheckPressure7, RecheckPressure8,

    RecheckPressure9, RecheckPressure10, RecheckAvePressure1,

    RecheckAvePressure2, RecheckAvePressure3, RecheckAvePressure4,

    RecheckAvePressure5, RecheckAvePressure6, RecheckAvePressure7,

    RecheckAvePressure8, RecheckAvePressure9, RecheckAvePressure10,

    [Gross Leakage], NHCurrentAt475, NHCurrentAt03, NLCurrentAt460,

    NLCurrentAt03, FlowAt485, CurrentAt485)

    select

    TestID, SolID, crs2 /*RawSweepID*/, ModuleSN, SSN, Passed, [DateTime],

    [Type], [Description], Operator, Comments, SolenoidType,

    SweepTable, Kp, Ki, AdlerPeriod, StepsinWave,

    SwitchingFrequency, DitherFrequency, PurgeTime, SweepTime,

    FluidTemperature, AverageSupply, SupplyMinimum, SupplyMinimumat,

    SupplyMaximum, SupplyMaximumat, SupplyRange, Flowat0, Flowat850,

    MaximumFlow, MaximumFlowat, MaximumRippleinc, MaximumRippleincat,

    MaximumRippledec, MaximumRippledecat, MaximumGain, MaximumGainat,

    MaximumHysteresis, MaximumHysteresisat, RepeatAvgHysterisis,

    GatePoint1lowcurrent, GatePoint1lowpressure, GatePoint1highcurrent,

    GatePoint1highpressure, GatePoint2lowcurrent, GatePoint2lowpressure,

    GatePoint2highcurrent, GatePoint2highpressure, MinimumPressure,

    RawDataFileName, Step1Pressureinc, Step2Pressureinc, Step3Pressureinc,

    Step4Pressureinc, Step5Pressureinc, Step6Pressureinc, Step7Pressureinc,

    Step8Pressureinc, Step9Pressureinc, Step10Pressureinc,

    Step1PressureAverage, Step2PressureAverage, Step3PressureAverage,

    Step4PressureAverage, Step5PressureAverage, Step6PressureAverage,

    Step7PressureAverage, Step8PressureAverage, Step9PressureAverage,

    Step10PressureAverage, RecheckPressure1, RecheckPressure2,

    RecheckPressure3, RecheckPressure4, RecheckPressure5,

    RecheckPressure6, RecheckPressure7, RecheckPressure8,

    RecheckPressure9, RecheckPressure10, RecheckAvePressure1,

    RecheckAvePressure2, RecheckAvePressure3, RecheckAvePressure4,

    RecheckAvePressure5, RecheckAvePressure6, RecheckAvePressure7,

    RecheckAvePressure8, RecheckAvePressure9, RecheckAvePressure10,

    [Gross Leakage], NHCurrentAt475, NHCurrentAt03, NLCurrentAt460,

    NLCurrentAt03, FlowAt485, CurrentAt485

    from [etswvsvexttst\SQLEXPRESS].[6f_module].[dbo].[tblvbssweepdata] a

    join [etswvsvexttst\sqlexpress].[6f_module].[dbo].[archivedtrs] b

    on (a.rawsweepid = b.rs and a.datetime = b.dt and

    a.testid=b.tst and a.solid=b.sol)

    set identity_insert [server_1905_test].[dbo].[tblvbssweepdata] off

    print char(13) + '----- Delete from 6f_module, tblvbssweepdata: ' + convert(char,getdate(),121)

    delete from [etswvsvexttst\SQLEXPRESS].[6f_module].[dbo].[tblvbssweepdata]

    where exists

    (select 'x' from [etswvsvexttst\sqlexpress].[6f_module].[dbo].[archivedtrs]

    where rs = rawsweepid

    and dt = [datetime]

    and tst = testid

    and sol = solid)

    /* - - - - - - - - - - */

    print char(13) + '----- Insert from 6f_module to server_1905_test, tbl_vbsrawsweep: ' + convert(char,getdate(),121)

    insert into [etswvsvsql003].[server_1905_test].[dbo].[tbl_vbsrawsweep]

    (rawsweepid, testid, solid, stepnumber, commandcurrent,

    ditheramplitude, steptime, supplypressure, [current],

    controlpressure, observedripple,

    observedditheramplitude, flow, interpolatedcurrent,

    interpolatedcontrolincp, interpolatedcontroldecp,

    hysteresis, averagecontrol, gain, [datetime], ssn)

    select

    crs2 /*rawsweepid*/, testid, solid, stepnumber, commandcurrent,

    ditheramplitude, steptime, supplypressure, [current],

    controlpressure, observedripple,

    observedditheramplitude, flow, interpolatedcurrent,

    interpolatedcontrolincp, interpolatedcontroldecp,

    hysteresis, averagecontrol, gain, [datetime], ssn

    from [etswvsvexttst\SQLEXPRESS].[6f_module].[dbo].[tbl_vbsrawsweep] a

    join [etswvsvexttst\SQLEXPRESS].[6f_module].[dbo].[archiverawsweep] b

    on (a.rawsweepid=b.rs and a.testid=b.tst and

    a.solid=b.sol and a.stepnumber=b.step)

    print char(13) + '----- Delete from 6f_module, tbl_vbsrawsweep: ' + convert(char,getdate(),121)

    delete from [etswvsvexttst\SQLEXPRESS].[6f_module].[dbo].[tbl_vbsrawsweep]

    where exists

    (select 'x' from [etswvsvexttst\SQLEXPRESS].[6f_module].[dbo].[archiverawsweep]

    where rs = rawsweepid

    and tst = testid

    and sol = solid

    and step = stepnumber)

    commit

    print '----- Transaction committed: ' + convert(char,getdate(),121)

    end try

    begin catch

    if @@trancount > 0

    rollback

    select @errmsg = error_message(),

    @err_severity = error_severity()

    raiserror(@errmsg, @err_severity, 1)

    end catch

    set xact_abort off

    print '----- Script end: ' + convert(char,getdate(),121)

    Results:

    ----- Script start: 2008-09-23 15:05:37.610

    ----- Getting cutoff date/time: 2008-09-23 15:05:37.610

    ------------------------------

    2008-09-23 15:00:37.610

    (1 row(s) affected)

    ----- Getting last data sweep raw id: 2008-09-23 15:05:37.610

    last data sweep id

    ------------------

    106255

    (1 row(s) affected)

    ----- Populate virtual table @dtrs: 2008-09-23 15:05:37.763

    (1 row(s) affected)

    ----- Populate virtual table @rawsweep: 2008-09-23 15:05:37.780

    (202 row(s) affected)

    ----- Update virtual tables with corrected raw sweep value: 2008-09-23 15:05:37.797

    (1 row(s) affected)

    (202 row(s) affected)

    ----- Show what will be copied: 2008-09-23 15:05:37.797

    dt rs tst sol crs2

    ----------------------- ----------- ----------- ----------- -----------

    2008-09-02 07:30:26.000 5 4 4 106256

    (1 row(s) affected)

    rs tst sol step crs2

    ----------- ----------- ----------- ----------- -----------

    5 4 4 0 106256

    5 4 4 1 106256

    5 4 4 2 106256

    5 4 4 3 106256

    5 4 4 4 106256

    5 4 4 5 106256

    5 4 4 6 106256

    5 4 4 7 106256

    5 4 4 8 106256

    5 4 4 9 106256

    5 4 4 10 106256

    5 4 4 11 106256

    5 4 4 12 106256

    5 4 4 13 106256

    5 4 4 14 106256

    5 4 4 15 106256

    5 4 4 16 106256

    5 4 4 17 106256

    5 4 4 18 106256

    5 4 4 19 106256

    5 4 4 20 106256

    5 4 4 21 106256

    5 4 4 22 106256

    5 4 4 23 106256

    5 4 4 24 106256

    5 4 4 25 106256

    5 4 4 26 106256

    5 4 4 27 106256

    5 4 4 28 106256

    5 4 4 29 106256

    5 4 4 30 106256

    5 4 4 31 106256

    5 4 4 32 106256

    5 4 4 33 106256

    5 4 4 34 106256

    5 4 4 35 106256

    5 4 4 36 106256

    5 4 4 37 106256

    5 4 4 38 106256

    5 4 4 39 106256

    5 4 4 40 106256

    5 4 4 41 106256

    5 4 4 42 106256

    5 4 4 43 106256

    5 4 4 44 106256

    5 4 4 45 106256

    5 4 4 46 106256

    5 4 4 47 106256

    5 4 4 48 106256

    5 4 4 49 106256

    5 4 4 50 106256

    5 4 4 51 106256

    5 4 4 52 106256

    5 4 4 53 106256

    5 4 4 54 106256

    5 4 4 55 106256

    5 4 4 56 106256

    5 4 4 57 106256

    5 4 4 58 106256

    5 4 4 59 106256

    5 4 4 60 106256

    5 4 4 61 106256

    5 4 4 62 106256

    5 4 4 63 106256

    5 4 4 64 106256

    5 4 4 65 106256

    5 4 4 66 106256

    5 4 4 67 106256

    5 4 4 68 106256

    5 4 4 69 106256

    5 4 4 70 106256

    5 4 4 71 106256

    5 4 4 72 106256

    5 4 4 73 106256

    5 4 4 74 106256

    5 4 4 75 106256

    5 4 4 76 106256

    5 4 4 77 106256

    5 4 4 78 106256

    5 4 4 79 106256

    5 4 4 80 106256

    5 4 4 81 106256

    5 4 4 82 106256

    5 4 4 83 106256

    5 4 4 84 106256

    5 4 4 85 106256

    5 4 4 86 106256

    5 4 4 87 106256

    5 4 4 88 106256

    5 4 4 89 106256

    5 4 4 90 106256

    5 4 4 91 106256

    5 4 4 92 106256

    5 4 4 93 106256

    5 4 4 94 106256

    5 4 4 95 106256

    5 4 4 96 106256

    5 4 4 97 106256

    5 4 4 98 106256

    5 4 4 99 106256

    5 4 4 100 106256

    5 4 4 101 106256

    5 4 4 102 106256

    5 4 4 103 106256

    5 4 4 104 106256

    5 4 4 105 106256

    5 4 4 106 106256

    5 4 4 107 106256

    5 4 4 108 106256

    5 4 4 109 106256

    5 4 4 110 106256

    5 4 4 111 106256

    5 4 4 112 106256

    5 4 4 113 106256

    5 4 4 114 106256

    5 4 4 115 106256

    5 4 4 116 106256

    5 4 4 117 106256

    5 4 4 118 106256

    5 4 4 119 106256

    5 4 4 120 106256

    5 4 4 121 106256

    5 4 4 122 106256

    5 4 4 123 106256

    5 4 4 124 106256

    5 4 4 125 106256

    5 4 4 126 106256

    5 4 4 127 106256

    5 4 4 128 106256

    5 4 4 129 106256

    5 4 4 130 106256

    5 4 4 131 106256

    5 4 4 132 106256

    5 4 4 133 106256

    5 4 4 134 106256

    5 4 4 135 106256

    5 4 4 136 106256

    5 4 4 137 106256

    5 4 4 138 106256

    5 4 4 139 106256

    5 4 4 140 106256

    5 4 4 141 106256

    5 4 4 142 106256

    5 4 4 143 106256

    5 4 4 144 106256

    5 4 4 145 106256

    5 4 4 146 106256

    5 4 4 147 106256

    5 4 4 148 106256

    5 4 4 149 106256

    5 4 4 150 106256

    5 4 4 151 106256

    5 4 4 152 106256

    5 4 4 153 106256

    5 4 4 154 106256

    5 4 4 155 106256

    5 4 4 156 106256

    5 4 4 157 106256

    5 4 4 158 106256

    5 4 4 159 106256

    5 4 4 160 106256

    5 4 4 161 106256

    5 4 4 162 106256

    5 4 4 163 106256

    5 4 4 164 106256

    5 4 4 165 106256

    5 4 4 166 106256

    5 4 4 167 106256

    5 4 4 168 106256

    5 4 4 169 106256

    5 4 4 170 106256

    5 4 4 171 106256

    5 4 4 172 106256

    5 4 4 173 106256

    5 4 4 174 106256

    5 4 4 175 106256

    5 4 4 176 106256

    5 4 4 177 106256

    5 4 4 178 106256

    5 4 4 179 106256

    5 4 4 180 106256

    5 4 4 181 106256

    5 4 4 182 106256

    5 4 4 183 106256

    5 4 4 184 106256

    5 4 4 185 106256

    5 4 4 186 106256

    5 4 4 187 106256

    5 4 4 188 106256

    5 4 4 189 106256

    5 4 4 190 106256

    5 4 4 191 106256

    5 4 4 192 106256

    5 4 4 193 106256

    5 4 4 194 106256

    5 4 4 195 106256

    5 4 4 196 106256

    5 4 4 197 106256

    5 4 4 198 106256

    5 4 4 199 106256

    5 4 4 200 106256

    5 4 4 201 106256

    (202 row(s) affected)

    ----- Starting transaction: 2008-09-23 15:05:37.810

    ----- Purge 6f_module temp table archivedtrs: 2008-09-23 15:05:37.810

    (1 row(s) affected)

    ----- Send @dtrs to linked server, archivedtrs: 2008-09-23 15:05:37.810

    (1 row(s) affected)

    ----- Purge 6f_module temp table archiverawsweep: 2008-09-23 15:05:37.810

    (91 row(s) affected)

    ----- Send @dtrs to linked server, archiverawsweep: 2008-09-23 15:05:37.810

    (202 row(s) affected)

    ----- Insert from 6f_module to server_1905_test, tblvbssweepdata: 2008-09-23 15:05:37.950

    (1 row(s) affected)

    ----- Delete from 6f_module, tblvbssweepdata: 2008-09-23 15:05:38.013

    (1 row(s) affected)

    ----- Insert from 6f_module to server_1905_test, tbl_vbsrawsweep: 2008-09-23 15:05:38.343

    (202 row(s) affected)

    ----- Delete from 6f_module, tbl_vbsrawsweep: 2008-09-23 15:05:38.687

    (202 row(s) affected)

    ----- Transaction committed: 2008-09-23 15:06:11.030

    ----- Script end: 2008-09-23 15:06:11.030

    Thanks everyone for your help. Will run the "whole" query tonight on the test servers for timing information.

Viewing post 16 (of 15 total)

You must be logged in to reply to this topic. Login to reply