kvdi765
asked on
linked server one connection whole procedure
i have following part of procedure
-- PRODUCT SPECIALIST
-- Cursor om alle benodigde data op te halen
DECLARE CSR_ProdSpec CURSOR FAST_FORWARD
FOR SELECT DISTINCT BrandID, ProductGroupID FROM Item.ItemTemp
-- Cursor openen om de data te overlopen
OPEN CSR_ProdSpec
-- Eerste record opvragen
FETCH NEXT FROM CSR_ProdSpec
INTO @Brand, @ProdGroup
-- Loopen zolang er records gevonden zijn
WHILE (@@FETCH_STATUS = 0)
BEGIN
-- Voor het merk in Eproc enkel de eerste 5 characters nemen
SET @TempBrand = LEFT(@Brand,5)
-- De ProductSpecialist ophalen voor dit artikel
SET @OracleCall = 'SELECT @TempEmplId = EmplId FROM OPENQUERY(Lnk_DolmenReport ingEproc2, ''SELECT OFFR.PKG_CREART.sf_bepaal_ productman ager(''''' + @TempBrand + ''''',''''' + @ProdGroup + ''''',''''' + @DefaultMgr + ''''') AS EmplId FROM DUAL'')'
SET @OracleParams = N'@TempEmplId varchar(5) OUTPUT'
EXEC sp_executesql @OracleCall, @OracleParams, @TempEmplId = @TempSpecialist OUTPUT
-- De P van het EmployeeID afhalen
SET @ProdSpecialist = LEFT(@TempSpecialist,4)
-- Items met deze Brand en ProdGroup updaten met de product specialist
UPDATE Item.ItemTemp
SET ProductSpecialist = @ProdSpecialist
WHERE BrandID = @Brand
AND ProductGroupID = @ProdGroup
-- Volgende record ophalen
FETCH NEXT FROM CSR_ProdSpec
INTO @Brand, @ProdGroup
END
-- Cursor afsluiten en verwijderen
CLOSE CSR_ProdSpec
DEALLOCATE CSR_ProdSpec
for each record in the cursor we submit a function on a oracle database with a linked server
my opinion is that if we have 5000 records in the cursor, that he is gonna make 5000 times
a connection with oracle through the linked server
for 5000 records it takes 15 minutes at the moment
is there a possibility to open the linked server connection once in the beginning of the procedure
and end it at the end of the procedure
this will save us much time i think
any help is welcome
greetings
-- PRODUCT SPECIALIST
-- Cursor om alle benodigde data op te halen
DECLARE CSR_ProdSpec CURSOR FAST_FORWARD
FOR SELECT DISTINCT BrandID, ProductGroupID FROM Item.ItemTemp
-- Cursor openen om de data te overlopen
OPEN CSR_ProdSpec
-- Eerste record opvragen
FETCH NEXT FROM CSR_ProdSpec
INTO @Brand, @ProdGroup
-- Loopen zolang er records gevonden zijn
WHILE (@@FETCH_STATUS = 0)
BEGIN
-- Voor het merk in Eproc enkel de eerste 5 characters nemen
SET @TempBrand = LEFT(@Brand,5)
-- De ProductSpecialist ophalen voor dit artikel
SET @OracleCall = 'SELECT @TempEmplId = EmplId FROM OPENQUERY(Lnk_DolmenReport
SET @OracleParams = N'@TempEmplId varchar(5) OUTPUT'
EXEC sp_executesql @OracleCall, @OracleParams, @TempEmplId = @TempSpecialist OUTPUT
-- De P van het EmployeeID afhalen
SET @ProdSpecialist = LEFT(@TempSpecialist,4)
-- Items met deze Brand en ProdGroup updaten met de product specialist
UPDATE Item.ItemTemp
SET ProductSpecialist = @ProdSpecialist
WHERE BrandID = @Brand
AND ProductGroupID = @ProdGroup
-- Volgende record ophalen
FETCH NEXT FROM CSR_ProdSpec
INTO @Brand, @ProdGroup
END
-- Cursor afsluiten en verwijderen
CLOSE CSR_ProdSpec
DEALLOCATE CSR_ProdSpec
for each record in the cursor we submit a function on a oracle database with a linked server
my opinion is that if we have 5000 records in the cursor, that he is gonna make 5000 times
a connection with oracle through the linked server
for 5000 records it takes 15 minutes at the moment
is there a possibility to open the linked server connection once in the beginning of the procedure
and end it at the end of the procedure
this will save us much time i think
any help is welcome
greetings
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh yes, I see what you mean.
Can you set up the oracle provider so it does connection pooling?
ASKER
the openquery statement just demands you to put the name of the linked server in the statement
and in sql statement we use the 4 part name
it is just that the openquery statement (which we use to call a function in oracle) makes
every time a connection i think instead that i want that the connection once made
has to stay open for whole the procedure