Showing posts with label back. Show all posts
Showing posts with label back. Show all posts

Wednesday, March 28, 2012

Poor Performance from Web Server

Hi,

I am having a problem with one of my stored procedures in SQL Server 2005. Basically the proc brings back a data set for the ASP.NET front end, but it is running very slowly from .NET.

I have run SQL profiler on the procedure and its taking around 20 seconds to bring back the data for the .NET, where as if I copy and paste the executed SP from profiler into the management studio and run it in a query window, it runs in around 1 second, even if I run DBCC DROPCLEANBUFFERS before I run it. More worryingly, the CPU usage is 40 times higher and the number of reads is 50% higher from .NET.

We have the .NET front end spread over 3 clustered web servers with load balancers and the SQL db is on a dedicated rig. I am having the same problem on my locally published version of the site as well, so I don't think it's an issue with the web site.

If anyone has got any ideas on this then please let me know as I am completely stuck. I should mention that the issue has only recently started occuring and it used to be fine and the rest of the site is fine...

Thanks in advance

Tom



maybe put some trace statements to echo out the time it execute a line of code. This way you can maybe find the bottleneck in your DAL. Are you using the Data Access Application Blocks. I have found those to be very valuable to manage my connections. I never see issues like you are describing anymore. Back in the day, like 4 years ago maybe when I was doing things on my own. Are you trying to fill a custom list or collection with a large set of records? I found that takes way too long and just op for datasets, readers or change my procedure to return a fixed set of rows.

But try the tracing thing to see what line(s) take the longest to execute and I think you will find your issue.

Friday, March 23, 2012

Point-in-time recovery using Log file backups newer than full back

Hopefully I can ask this question w/o too much confusion. The example I am
about to give may not be practical, but the answer should help me understand
db and log backups a little better.
Scenario:
Full db backup performed 3 times in a day - morning, afternoon, and evening
(T1, T2, T3 respectively)
Log backup performed in morning (T1) and evening (T3) immediately after the
morning full db backups (no afternoon (T2) log backup)
Then server db drive fails after the evening db and log backups
The evening full backup is unrestorable (bad tape)
The evening log backup is good (stored on another device).
Could I restore the db to the point of failure using the afternoon full db
backup (T2) and the evening log backup (T3)?
db: T1--T2--T3
log: T1--T3
In other words, when restoring the evening log backup, against the afternoon
full db backup, would the restore process read through the evening log backup
to find the transactions begining at T2, or does the log being restored need
to be from a backup that occurs after the full backup was created?
My "guess" is that the restore would read through the T3 log and apply the
transactions that began after the T2 full db backup.If you ask whether you can "skip" a db backup, then the answer it yes. You cannot "skip" a log
backup, though. Perhaps easier with an examples. Say the time goes from top to bottom:
A Db
B Log
C Log
D Db
E Log
F Log
G Db
H Log
I Log
Here are a couple of examples of what you *can* do:
a, b, c, d, e, h, i
d, e, f, h, i
g, h, i
Here's a couple of examples of what you *cannot* do:
a, c, e, f, h, i
a, e, f, h, i
Short answer is that you need an unbroken chain of log backup. Db backups in between do not matter.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"GRakaska" <GRakaska@.discussions.microsoft.com> wrote in message
news:E20FF009-56C4-4B91-A31A-9720FB1404CD@.microsoft.com...
> Hopefully I can ask this question w/o too much confusion. The example I am
> about to give may not be practical, but the answer should help me understand
> db and log backups a little better.
> Scenario:
> Full db backup performed 3 times in a day - morning, afternoon, and evening
> (T1, T2, T3 respectively)
> Log backup performed in morning (T1) and evening (T3) immediately after the
> morning full db backups (no afternoon (T2) log backup)
> Then server db drive fails after the evening db and log backups
> The evening full backup is unrestorable (bad tape)
> The evening log backup is good (stored on another device).
> Could I restore the db to the point of failure using the afternoon full db
> backup (T2) and the evening log backup (T3)?
> db: T1--T2--T3
> log: T1--T3
> In other words, when restoring the evening log backup, against the afternoon
> full db backup, would the restore process read through the evening log backup
> to find the transactions begining at T2, or does the log being restored need
> to be from a backup that occurs after the full backup was created?
> My "guess" is that the restore would read through the T3 log and apply the
> transactions that began after the T2 full db backup.
>|||> A Db
> B Log
> C Log
> D Db
> E Log
> F Log
> G Db
> H Log
> I Log
> Here are a couple of examples of what you *can* do:
> a, b, c, d, e, h, i
> d, e, f, h, i
> g, h, i
I think an error has found it's way in the first row. You can't skip the F,
since that will break the log chain - and you also say that the chain can
not be broken :)
/Sjang|||> I think an error has found it's way in the first row.
Yes, thanks for catching that. It should have been:
a, b, c, e, f, h, i
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Henrik Davidsen" <none@.none.dk> wrote in message news:lBBDj.7440$9m.7234@.fe25.usenetserver.com...
>> A Db
>> B Log
>> C Log
>> D Db
>> E Log
>> F Log
>> G Db
>> H Log
>> I Log
>> Here are a couple of examples of what you *can* do:
>> a, b, c, d, e, h, i
>> d, e, f, h, i
>> g, h, i
>
> I think an error has found it's way in the first row. You can't skip the F,
> since that will break the log chain - and you also say that the chain can
> not be broken :)
> /Sjang
>
>

Pointing my new .ADP file to my new SQL Server DB

I hope this question belongs in this forum.

I have a .ADP application (access 2000 front end, SQL Server 2000 back end)
I basically want to create a new .ADP file and point it to a different SQL Server 2000 Database.

I've copied the current SQL Server DB and recreated it. Same for the .ADP file, but it is currently pointing to the old Db, where do I go to have it point to the new SQL Server DB?

Thanksi figured this out thanks.|||You know, you don't need to create a copy of the ADP file. You can easily change the datasource as long as the schemas in both databases are the same.

Pointing access to SQL

Hello~

Just trying to get back in the swing of things in server business. I just brought over a database from on SQL server. Now back on the clients machine it is still bringing up the old database. How can I get the client to point to the correct database on the new server? I hope someone can help ThanksYou are trying to get an access app pointing to a sql db yes?

You should be able to link the tables into access by setting up and ODBC dsn that points to the sql database.

I don't know if this is a good way to work though...

Also your table names will be prefixed with the table owner name so you will have to change all the names after you link them...

hope that helps.|||Originally posted by rokslide
You are trying to get an access app pointing to a sql db yes?

You should be able to link the tables into access by setting up and ODBC dsn that points to the sql database.

I don't know if this is a good way to work though...

Also your table names will be prefixed with the table owner name so you will have to change all the names after you link them...

hope that helps.

Yes I am doing application pointing. I will try this any other ways you can think of? Thanks for your time|||It really depends on the application you are wanting to point at SQL.

If it's MSAccess then linking tables would be one solution. Another would be using ADODB and doing it programaticly.

What is the application you are trying to point to sql?|||I am wanting to link Access databases to a different sql. sorry that I didn't put that in.|||Okie, so there are linked tbales in the MS Access application you have now?

If so I understand that you can change the connection details for the link. Working off memory (I did this ages ago) there is a field in the properties of the table that specifies the server that you are connecting into.

Have a look and see what you can find...sql

Point in time restore - cannot change date

I am trying to roll back a SQL Server 2000 database to a previous point
in time, but I am not allowed to select the date I want in the 'point
in time' dialog - it always reverts back to the date of the transaction
log backup.
So far, I have done the following, in the following order:
1. Backed up the database.
2. Backed up the transaction log.
3. Restored the database from a previous backup.
4. Do a 'point in time restore' from the transaction log backup
completed in step 2.
At step 4, if I follow through with the restore, choosing the date and
time of the log backup as my 'point in time', I sucessfully get the
data I started with.
Can anyone tell me why I cannot specify a 'point in time' of, say, five
days ago - and, more importantly, *how* to specify another point in
time? If the transaction log has the data to restore my database to the
point at which the log backup was taken, surely it has the data to
restore to a point a few days earlier.
Thanks,
Joejoe
Do you perfom it from EM, right?
There is very good topic ( with examples) about it in the BOL
"joe" <joe.hodsdon@.gmail.com> wrote in message
news:1155098591.530691.44480@.n13g2000cwa.googlegroups.com...
>I am trying to roll back a SQL Server 2000 database to a previous point
> in time, but I am not allowed to select the date I want in the 'point
> in time' dialog - it always reverts back to the date of the transaction
> log backup.
> So far, I have done the following, in the following order:
> 1. Backed up the database.
> 2. Backed up the transaction log.
> 3. Restored the database from a previous backup.
> 4. Do a 'point in time restore' from the transaction log backup
> completed in step 2.
> At step 4, if I follow through with the restore, choosing the date and
> time of the log backup as my 'point in time', I sucessfully get the
> data I started with.
> Can anyone tell me why I cannot specify a 'point in time' of, say, five
> days ago - and, more importantly, *how* to specify another point in
> time? If the transaction log has the data to restore my database to the
> point at which the log backup was taken, surely it has the data to
> restore to a point a few days earlier.
> Thanks,
> Joe
>|||Hi Uri,
Thanks for the reply. Yes, I'm working in EM. I reviewed the Books
Online before doing anything - that's where I got much of my
instruction. According to the "How to restore a point in time" article
in BOL, I should be able to specify a date and time to which I want to
restore. But EM won't let me change the date.
Thanks again,
Joe
Uri Dimant wrote:[vbcol=seagreen]
> joe
> Do you perfom it from EM, right?
> There is very good topic ( with examples) about it in the BOL
> "joe" <joe.hodsdon@.gmail.com> wrote in message
> news:1155098591.530691.44480@.n13g2000cwa.googlegroups.com...|||Joe,
I remember an issue in SQL2000 with point in time restore from EM.
Actually the very first time you try to restore a database from EM
point in time restore doesn't work. You have to do it from QA using the
SQL statements. I thought it has been fixed in one of the service packs
but don't remember which one.
Markus|||Thank you, I'll give that a try.
Joe
MarkusB wrote:
> Joe,
> I remember an issue in SQL2000 with point in time restore from EM.
> Actually the very first time you try to restore a database from EM
> point in time restore doesn't work. You have to do it from QA using the
> SQL statements. I thought it has been fixed in one of the service packs
> but don't remember which one.
> Markus

Point in time restore - cannot change date

I am trying to roll back a SQL Server 2000 database to a previous point
in time, but I am not allowed to select the date I want in the 'point
in time' dialog - it always reverts back to the date of the transaction
log backup.
So far, I have done the following, in the following order:
1. Backed up the database.
2. Backed up the transaction log.
3. Restored the database from a previous backup.
4. Do a 'point in time restore' from the transaction log backup
completed in step 2.
At step 4, if I follow through with the restore, choosing the date and
time of the log backup as my 'point in time', I sucessfully get the
data I started with.
Can anyone tell me why I cannot specify a 'point in time' of, say, five
days ago - and, more importantly, *how* to specify another point in
time? If the transaction log has the data to restore my database to the
point at which the log backup was taken, surely it has the data to
restore to a point a few days earlier.
Thanks,
Joejoe
Do you perfom it from EM, right?
There is very good topic ( with examples) about it in the BOL
"joe" <joe.hodsdon@.gmail.com> wrote in message
news:1155098591.530691.44480@.n13g2000cwa.googlegroups.com...
>I am trying to roll back a SQL Server 2000 database to a previous point
> in time, but I am not allowed to select the date I want in the 'point
> in time' dialog - it always reverts back to the date of the transaction
> log backup.
> So far, I have done the following, in the following order:
> 1. Backed up the database.
> 2. Backed up the transaction log.
> 3. Restored the database from a previous backup.
> 4. Do a 'point in time restore' from the transaction log backup
> completed in step 2.
> At step 4, if I follow through with the restore, choosing the date and
> time of the log backup as my 'point in time', I sucessfully get the
> data I started with.
> Can anyone tell me why I cannot specify a 'point in time' of, say, five
> days ago - and, more importantly, *how* to specify another point in
> time? If the transaction log has the data to restore my database to the
> point at which the log backup was taken, surely it has the data to
> restore to a point a few days earlier.
> Thanks,
> Joe
>|||Hi Uri,
Thanks for the reply. Yes, I'm working in EM. I reviewed the Books
Online before doing anything - that's where I got much of my
instruction. According to the "How to restore a point in time" article
in BOL, I should be able to specify a date and time to which I want to
restore. But EM won't let me change the date.
Thanks again,
Joe
Uri Dimant wrote:
> joe
> Do you perfom it from EM, right?
> There is very good topic ( with examples) about it in the BOL
> "joe" <joe.hodsdon@.gmail.com> wrote in message
> news:1155098591.530691.44480@.n13g2000cwa.googlegroups.com...
> >I am trying to roll back a SQL Server 2000 database to a previous point
> > in time, but I am not allowed to select the date I want in the 'point
> > in time' dialog - it always reverts back to the date of the transaction
> > log backup.
> >
> > So far, I have done the following, in the following order:
> >
> > 1. Backed up the database.
> > 2. Backed up the transaction log.
> > 3. Restored the database from a previous backup.
> > 4. Do a 'point in time restore' from the transaction log backup
> > completed in step 2.
> >
> > At step 4, if I follow through with the restore, choosing the date and
> > time of the log backup as my 'point in time', I sucessfully get the
> > data I started with.
> >
> > Can anyone tell me why I cannot specify a 'point in time' of, say, five
> > days ago - and, more importantly, *how* to specify another point in
> > time? If the transaction log has the data to restore my database to the
> > point at which the log backup was taken, surely it has the data to
> > restore to a point a few days earlier.
> >
> > Thanks,
> > Joe
> >|||Joe,
I remember an issue in SQL2000 with point in time restore from EM.
Actually the very first time you try to restore a database from EM
point in time restore doesn't work. You have to do it from QA using the
SQL statements. I thought it has been fixed in one of the service packs
but don't remember which one.
Markus|||Thank you, I'll give that a try.
Joe
MarkusB wrote:
> Joe,
> I remember an issue in SQL2000 with point in time restore from EM.
> Actually the very first time you try to restore a database from EM
> point in time restore doesn't work. You have to do it from QA using the
> SQL statements. I thought it has been fixed in one of the service packs
> but don't remember which one.
> Markus

Point in time restore

Is it possible?

I have no Backups at all.
And I dropped a important table completely.
Is there anyway to roll back this command.

I am guessing that the transaction log keeps this inforation and its still there. I think with other 3rd party tools you can recover to a point in time without backups so there must be a way we can do it without 3rd party tools , cant it?

Your 'best' option at this point is to immediately download an eval copy of one of the Third party log tools. Many are fully functioning for 14-30 days.

But since you indicated you have no backups, if by some bad karma your database is in 'Simple' mode and you may be SOL.

|||Is there anyother way without 3rd party tools.
its a Full Recovery Model.
what is meant by > you may be SOL. <
|||

Download Lumnigents' Log Exlorer, or ApexSQL's SQLLog -or one of the several other good log tools.

It is just not worth any time and effort to try this without their help.

*SOL = "Sorry, Out of Luck"

|||

what is u r backup policy ... if u have full backup and subsequent transaction log backup it is possible to restore to the time just before u deleted the table... Read about STOP AT option in Restore Database...

suppose

(a) 06 Mar 07 you deleted the table at 1000 AM...

(b) U have full backup of 05 Mar 07 20:00 hrs (8 PM)

(c) your database is in Full recovery model

(d) you have no differential backup

(e) you have no TL backup

06 Mar 07 15:00 hrs you found that the data has been delete by mistake and u need to get the databack

(a) first and foremost thing is to take the TL backup

(b) restore the full backup of 05 Mar 07 20:00 hrs as a new database with No REcovery option

(c) Restore the TL with STOPAT 09:55 hrs with Recovery option

this is just a scenario which u can relate and try to get the data back

Madhu

|||I am aware of the stop at option and the scenario you mentioned.
But i am thinking of the worst-worst case scenario. What if you have no backups at all.
you deleted a table.
now u need to recover that table. How do you go about doing that without any backups.

If the history is kept in the transactional logs then it seems correct to assume that you can recover a table dropped 5 minutes before from the transactional logs.

Can we achive such a thing without using third party tools. worst case scenario.

Thanks everyone..|||

In simple terms, as I've tried to communicate to you a couple of times -NO!

If you need to do this, get a third party tool.

|||

Just out of interest, I've noticed that SQL 2005's RESTORE DATABASE command now has a STOPAT option, however BOL doesn't give much information away as to how/under what circumstances this option can be used.

I gave it quick a test earlier on today but couldn't get it to work. Does anyone have any experience of using it? I was wondering if it could possibly be of use to the original poster of this thread (i.e. by taking a full backup now, and if the log hasn't been backed-up, then is it possible to restore to a point in time earlier than the full backup? - my guess is 'probably not', although in theory surely this should be possible by examining the log and rolling back / undoing all uncommitted and comitted transactions to the point in time specified?).

Thanks
Chris

|||

It seems to me that if you make a 'Full Backup' at this juncture, ALL committed activities would be assumed to be in the database, and the transaction log would be truncated. Then not only would the table to permanently 'gone', but any record of it would no longer be in the transaction log.

The missing element is the previous 'Backup' -it does not exist, therefore, the only vestiges of the missing table (if other than page logging) 'might' be in the existing transaction log. Lunmigent's Log explorer would help find out IF there is any chance of recovering the data.

|||

Just one thing, though, taking a full database backup does not truncate the transaction log - this is one of the reasons why I was wondering whether the STOPAT option in the RESTORE DATABASE command would be of use. Agreed that a log-reader tool would be a good tool to invest in / trial if not.

Chris

Wednesday, March 21, 2012

Point in time recovery issue

Hey all,
I've been playing around with point in time recoveries and
encountered a weird issue. Some background info:
I performed a full back, a differential and then some transaction log
backups. I made data changes at set intervals and I can recover to
points in time between those without any issue.
Here's the problem... When you click on point in time recovery a
window pops up prompting you for a time. The default thats in there
appears to be the time of the last transaction log, so i'm assuming
that would be the maximum time you could restore to. If I click on
OK the restore proceeds and completes successfully. But, when I go
back to the EM console the database is marked as Loading and in the
logfile it says:
Bypassing recovery for database 'myTest' because it is marked IN LOAD.
If I repeat the process and do another point in time recovery but
select a time 10 seconds before the default time the database recovers
fine. If I do a full restore using the last transaction log it works
fine as well.
I searched on google, technet, etc but no luck... I'm not overly
concerned but curious as to why the database isn't recovering
properly.
DaveCould it be that you for some reason didn't specify WITH RECOVERY for that
last log restore? Try doing this using TSQL instead of EM (you can catch the
commands that EM sends with Profiler and then execute them in query
analyzer. And make sure that you specify WITH RECOVERY for that last log
restore.
--
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"Dave" <shoad316@.hotmail.com> wrote in message
news:78cf0572.0311110909.4a320140@.posting.google.com...
> Hey all,
> I've been playing around with point in time recoveries and
> encountered a weird issue. Some background info:
> I performed a full back, a differential and then some transaction log
> backups. I made data changes at set intervals and I can recover to
> points in time between those without any issue.
> Here's the problem... When you click on point in time recovery a
> window pops up prompting you for a time. The default thats in there
> appears to be the time of the last transaction log, so i'm assuming
> that would be the maximum time you could restore to. If I click on
> OK the restore proceeds and completes successfully. But, when I go
> back to the EM console the database is marked as Loading and in the
> logfile it says:
> Bypassing recovery for database 'myTest' because it is marked IN LOAD.
> If I repeat the process and do another point in time recovery but
> select a time 10 seconds before the default time the database recovers
> fine. If I do a full restore using the last transaction log it works
> fine as well.
> I searched on google, technet, etc but no luck... I'm not overly
> concerned but curious as to why the database isn't recovering
> properly.
> Dave|||Thanks for the info, I was using EM to do the recover and in the options tab
it defaults to full recovery I believe.
I'm new to SQL Server so i'm not familiar with using the CL yet but i'll
give it a shot tomorrow.
thanks
--
--
david.best@.sympatico.ca
"Thanks to the remote control I have the attention span of a gerbil!"
"There are 10 types of people in the world. Those who understand binary,
and those who don't."
"Tibor Karaszi" <tibor.please_reply_to_public_forum.karaszi@.cornerstone.se>
wrote in message news:%235gDHxIqDHA.1096@.TK2MSFTNGP11.phx.gbl...
> Could it be that you for some reason didn't specify WITH RECOVERY for that
> last log restore? Try doing this using TSQL instead of EM (you can catch
the
> commands that EM sends with Profiler and then execute them in query
> analyzer. And make sure that you specify WITH RECOVERY for that last log
> restore.
> --
> Tibor Karaszi, SQL Server MVP
> Archive at:
>
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
>
> "Dave" <shoad316@.hotmail.com> wrote in message
> news:78cf0572.0311110909.4a320140@.posting.google.com...
> > Hey all,
> >
> > I've been playing around with point in time recoveries and
> > encountered a weird issue. Some background info:
> >
> > I performed a full back, a differential and then some transaction log
> > backups. I made data changes at set intervals and I can recover to
> > points in time between those without any issue.
> >
> > Here's the problem... When you click on point in time recovery a
> > window pops up prompting you for a time. The default thats in there
> > appears to be the time of the last transaction log, so i'm assuming
> > that would be the maximum time you could restore to. If I click on
> > OK the restore proceeds and completes successfully. But, when I go
> > back to the EM console the database is marked as Loading and in the
> > logfile it says:
> >
> > Bypassing recovery for database 'myTest' because it is marked IN LOAD.
> >
> > If I repeat the process and do another point in time recovery but
> > select a time 10 seconds before the default time the database recovers
> > fine. If I do a full restore using the last transaction log it works
> > fine as well.
> >
> > I searched on google, technet, etc but no luck... I'm not overly
> > concerned but curious as to why the database isn't recovering
> > properly.
> >
> > Dave
>

Tuesday, March 20, 2012

PL-SQL to T-SQL trigger conv

Hi all,
I brought this up some time back, but I have a trigger that I was tasked,
begrudgingly, with converting from Oracle to SQLserver. After the comments
I received, which were great, it has me concerned that I'm trying to convert
line-for-line a trigger that might very well be poorly written in the first
place. Would any of you mind taking a look and giving me some feedback?
Unfortunately, I have no data tables to refer to myself, so can't provide
them to you.
I am going to attack the conversion in parts, and since I've already run
into some unfamiliar issues to deal with, I thought I'd ask before I go too
far down the road and find that the procedure has too many problems itself.
Trust me, I'd rather stick to my user interface code than have to deal with
converting a trigger. I'm only doing this to help the customer get through
where the vendor has given up.
CREATE OR REPLACE TRIGGER PartCost_WO AFTER INSERT ON PartTrans FOR EACH ROW
DECLARE
aNextVal NUMBER(9);
PricePer FLOAT;
BEGIN
IF (:new.HISTKEY) > 1 THEN
SELECT Z.NEXTVAL INTO aNextVal
FROM ZEQ_120 Z;
aNextVal := aNextVal + 1;
PricePer := :new.TRNCST/:new.PRTSISS;
INSERT INTO COSTPART
(USAGE, PRTKEY, STKKEY, TOTCOST, ADDDTTM, ADDBY, COSTKEY,
HISTKEY, CHRGDTTM, RATE)
VALUES
(:new.PRTSISS, :new.PRTKEY, :new.STKKEY, :new.TRNCST,
:new.ADDDTTM, 'PartCost_WO TRIGGER', aNextVal, :new.HISTKEY,
:new.ADDDTTM, PricePer);
UPDATE ZEQ_120 Z SET Z.NEXTVAL = Z.NEXTVAL + 1;
END IF;
END;
/
show errors trigger PartCost_WO;Mike
Have you looked at CREATE TRIGGER topic in the BOL?
CREATE TRIGGER PartCost_WO ON PartTrans FOR INSERT
DECLARE @.aNextVal DECIMAL or INT...
DECLARE @.PricePer FLOAT;
BEGIN
--Did not undesrtand what does it mean?
IF (:new.HISTKEY) > 1 THEN
SELECT Z.NEXTVAL INTO aNextVal
FROM ZEQ_120 Z;
SET @.aNextVal = @.aNextVal + 1;
SET @.PricePer := :new.TRNCST/:new.PRTSISS; --Where do these
columns/variables come from?
INSERT INTO COSTPART
(USAGE, PRTKEY, STKKEY, TOTCOST, ADDDTTM, ADDBY, COSTKEY,
HISTKEY, CHRGDTTM, RATE)
SELECT
new.PRTSISS, :new.PRTKEY, :new.STKKEY, :new.TRNCST,
:new.ADDDTTM, 'PartCost_WO TRIGGER', aNextVal, :new.HISTKEY,
:new.ADDDTTM, PricePer FROM SomeTable
UPDATE ZEQ_120 Z SET Z.NEXTVAL = Z.NEXTVAL + 1;--Don't you have a WHERE
condition here?
END;
"mikeb" <mike@.nohostanywhere.com> wrote in message
news:%23U5cDxwlFHA.3780@.tk2msftngp13.phx.gbl...
> Hi all,
> I brought this up some time back, but I have a trigger that I was tasked,
> begrudgingly, with converting from Oracle to SQLserver. After the
> comments I received, which were great, it has me concerned that I'm trying
> to convert line-for-line a trigger that might very well be poorly written
> in the first place. Would any of you mind taking a look and giving me
> some feedback? Unfortunately, I have no data tables to refer to myself, so
> can't provide them to you.
> I am going to attack the conversion in parts, and since I've already run
> into some unfamiliar issues to deal with, I thought I'd ask before I go
> too far down the road and find that the procedure has too many problems
> itself. Trust me, I'd rather stick to my user interface code than have to
> deal with converting a trigger. I'm only doing this to help the customer
> get through where the vendor has given up.
> CREATE OR REPLACE TRIGGER PartCost_WO AFTER INSERT ON PartTrans FOR EACH
> ROW
> DECLARE
> aNextVal NUMBER(9);
> PricePer FLOAT;
> BEGIN
> IF (:new.HISTKEY) > 1 THEN
> SELECT Z.NEXTVAL INTO aNextVal
> FROM ZEQ_120 Z;
> aNextVal := aNextVal + 1;
> PricePer := :new.TRNCST/:new.PRTSISS;
> INSERT INTO COSTPART
> (USAGE, PRTKEY, STKKEY, TOTCOST, ADDDTTM, ADDBY, COSTKEY,
> HISTKEY, CHRGDTTM, RATE)
> VALUES
> (:new.PRTSISS, :new.PRTKEY, :new.STKKEY, :new.TRNCST,
> :new.ADDDTTM, 'PartCost_WO TRIGGER', aNextVal, :new.HISTKEY,
> :new.ADDDTTM, PricePer);
> UPDATE ZEQ_120 Z SET Z.NEXTVAL = Z.NEXTVAL + 1;
> END IF;
> END;
> /
> show errors trigger PartCost_WO;
>
>
>|||Uri,
Here are some possible answers to your questions. Maybe you
can give it another shot - I'm reticent, because SQL Server doesn't
have FOR EACH ROW triggers, and it looks like this is trying to
emulate a home-grown identity-like column, which is tricky to do
all at once.
A FOR EACH ROW trigger will be executed once for each row
inserted, so what's needed here is a set-based query, a loop, or
a cursor.
The expression :new.<column> is probably the Oracle equivalent
of inserted.<column> for a row, so it can't be used in INSERT .. VALUES,
but you can do INSERT INTO .. SELECT .. FROM inserted.
aNextVal is a variable, so SELECT Z.NEXTVAL INTO aNextVal
is probably SET @.aNextVal = (SELECT Z.NEXTVAL FROM ZEQ_120 Z)
It looks very much like ZEQ_120 contains only one row, and that row
is the last home-grown identity value used. This would explain SELECT INTO
a variable, as well as the UPDATE of ZEQ_120 with no WHERE clause.
The hardest part of this is to get the incrementing column values that
go into
COSTPART correct. The key column of PartTrans would be helpful
to know here.
If this trigger will only be called for single-row inserts, then it's
easier, and
IF @.@.rowcount > 1 BEGIN <report error> <rollback transaction> END
can help out.
Steve Kass
Drew University
Uri Dimant wrote:

>Mike
>Have you looked at CREATE TRIGGER topic in the BOL?
>CREATE TRIGGER PartCost_WO ON PartTrans FOR INSERT
>DECLARE @.aNextVal DECIMAL or INT...
>DECLARE @.PricePer FLOAT;
>BEGIN
>--Did not undesrtand what does it mean?
> IF (:new.HISTKEY) > 1 THEN
> SELECT Z.NEXTVAL INTO aNextVal
> FROM ZEQ_120 Z;
>
> SET @.aNextVal = @.aNextVal + 1;
> SET @.PricePer := :new.TRNCST/:new.PRTSISS; --Where do these
>columns/variables come from?
> INSERT INTO COSTPART
> (USAGE, PRTKEY, STKKEY, TOTCOST, ADDDTTM, ADDBY, COSTKEY,
> HISTKEY, CHRGDTTM, RATE)
>SELECT
> new.PRTSISS, :new.PRTKEY, :new.STKKEY, :new.TRNCST,
>:new.ADDDTTM, 'PartCost_WO TRIGGER', aNextVal, :new.HISTKEY,
>:new.ADDDTTM, PricePer FROM SomeTable
>
>UPDATE ZEQ_120 Z SET Z.NEXTVAL = Z.NEXTVAL + 1;--Don't you have a WHERE
>condition here?
>
>END;
>"mikeb" <mike@.nohostanywhere.com> wrote in message
>news:%23U5cDxwlFHA.3780@.tk2msftngp13.phx.gbl...
>
>
>|||On Mon, 1 Aug 2005 19:45:23 -0700, mikeb wrote:
(snip)
>Trust me, I'd rather stick to my user interface code than have to deal with
>converting a trigger. I'm only doing this to help the customer get through
>where the vendor has given up.
Hi mikeb,
Okay. With the help of Uri and Steve, I think I can help you help the
customer get through <g>.
I agree with Steve: the ZEQ_120 table must contain just one row that
holds a "last used" value. This code really wouldn't make sense if it
were otherwise.
The easiest way to port this to SQL Server is to change the COSTKEY
column in the COSTPART table to an IDENTITY column. That way, SQL Server
will dish out a new, continuously increasing number. Without the need
for a seperate one-row "last number used" table, and without the locking
issues, deadlock opportunities and scalability restrictions that such a
table incurs.
Note however that the IDENTITY column does not guarantee that there are
no gaps. If a transaction aborts and is rolled back, the IDENTITY values
used in that transaction won't be reused. The Oracle code you posted
will reuse those values, since the change to the ZEQ_120 table will also
be rolled back.
If you can change COSTPART.COSTKEY to an identity column, the equivalent
trigger in SQL server becomes very easy:
CREATE TRIGGER PartCost_WO
ON PartTrans
AFTER INSERT
AS
INSERT INTO COSTPART
(USAGE, PRTKEY, STKKEY, TOTCOST, ADDDTTM, ADDBY,
HISTKEY, CHRGDTTM, RATE)
SELECT PRTSISS, PRTKEY, STKKEY, TRNCST, ADDTTM, 'PartCost_WO TRIGGER',
HISTKEY, ADDDTTM, TRNCST/PRTSISS
FROM inserted
go
Note that this changes the logic from a row-based trigger to a set-based
trigger (the only trigger type supported in SQL Server). Probably a lot
faster too.
Also, it might make sense to redefine COSTPART.RATE as a computed
column. Storing a value that can be computed from two other values in
the same row only makes sense if there's the possiblity that one of the
values might change at a later time without the others changing along.
But if RATE always has to be equal to TPRTKEY/USAGE, then it's better to
use a computed column.
Final advice: don't use all caps. Your code will be much eaasier to read
and understand if you use ALL CAPS for keywords, and PascalCase for
table and column names.
CREATE TABLE CostPart
(CostKey int NOT NULL IDENTITY,
-- other columns,
Rate AS PrtKey / Usage,
PRIMARY KEY (...),
-- other constraints,
)
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Thanks Hugo.
I couldn't agree with you more on all points - even down to the all caps and
confusing column names (oh wait, maybe that was my own peve).
Unfortunately, I can't change anything about the tables other than adding in
a trigger. This database was written for another vendors software, I'm only
augmenting it to make it work the way it should.
And you guys are right, the zeq_# table is used to gain a unique value for a
specific inserted column of data in a row. Again, I'd do this differently,
probably even without use of an identity column.
That aside, I appreciate all the comments and continued input! I'm just
very unfamiliar with oracle sql and only at the tip of the 'berg of t-sql
(as I continuously humble myself when reading through this NG).
Thanks again!
btw, here's how I converted the trigger so far -- no database yet in my
hands to be able to test it - but can I get some input? Would be very nice
to be able to insert it into a test database and have it work right from the
start!! But I don't know it enough to really test the logic against the
oracle code.
Create Trigger WO_PrtCost ON PRTTRNI After Insert
As
Declare @.aNextVal int
Declare @.PricePer float
Begin
If (Inserted.HISTKEY > 1)
Begin
SELECT @.aNextVal = Z.NEXTVAL FROM ZEQ_120 Z
Select @.aNextVal = @.aNextVal + 1
Select @.PricePer = Inserted.TRNCST/Inserted.PRTSISS
Insert COSTPART
(
USAGE,
PRTKEY,
STKKEY,
TOTCOST,
ADDDTTM,
ADDBY,
COSTKEY,
HISTKEY,
CHRGDTTM,
RATE
)
Select
PRTSISS,
PRTKEY,
STKKEY,
TRNCST,
ADDDTTM,
'WO_PRTCOST TRIGGER',
@.aNextVal,
HISTKEY,
ADDDTTM,
PricePer
From
Inserted
Update ZEQ_120
Set NEXTVAL = NEXTVAL + 1
End
End
--RaiseError('trigger WO_PRTCOST', 1, 1)
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:fgv4f1tf6q28otl42arm8q488m24ht2so2@.
4ax.com...
> On Mon, 1 Aug 2005 19:45:23 -0700, mikeb wrote:
> (snip)
> Hi mikeb,
> Okay. With the help of Uri and Steve, I think I can help you help the
> customer get through <g>.
> I agree with Steve: the ZEQ_120 table must contain just one row that
> holds a "last used" value. This code really wouldn't make sense if it
> were otherwise.
> The easiest way to port this to SQL Server is to change the COSTKEY
> column in the COSTPART table to an IDENTITY column. That way, SQL Server
> will dish out a new, continuously increasing number. Without the need
> for a seperate one-row "last number used" table, and without the locking
> issues, deadlock opportunities and scalability restrictions that such a
> table incurs.
> Note however that the IDENTITY column does not guarantee that there are
> no gaps. If a transaction aborts and is rolled back, the IDENTITY values
> used in that transaction won't be reused. The Oracle code you posted
> will reuse those values, since the change to the ZEQ_120 table will also
> be rolled back.
> If you can change COSTPART.COSTKEY to an identity column, the equivalent
> trigger in SQL server becomes very easy:
> CREATE TRIGGER PartCost_WO
> ON PartTrans
> AFTER INSERT
> AS
> INSERT INTO COSTPART
> (USAGE, PRTKEY, STKKEY, TOTCOST, ADDDTTM, ADDBY,
> HISTKEY, CHRGDTTM, RATE)
> SELECT PRTSISS, PRTKEY, STKKEY, TRNCST, ADDTTM, 'PartCost_WO TRIGGER',
> HISTKEY, ADDDTTM, TRNCST/PRTSISS
> FROM inserted
> go
> Note that this changes the logic from a row-based trigger to a set-based
> trigger (the only trigger type supported in SQL Server). Probably a lot
> faster too.
> Also, it might make sense to redefine COSTPART.RATE as a computed
> column. Storing a value that can be computed from two other values in
> the same row only makes sense if there's the possiblity that one of the
> values might change at a later time without the others changing along.
> But if RATE always has to be equal to TPRTKEY/USAGE, then it's better to
> use a computed column.
> Final advice: don't use all caps. Your code will be much eaasier to read
> and understand if you use ALL CAPS for keywords, and PascalCase for
> table and column names.
> CREATE TABLE CostPart
> (CostKey int NOT NULL IDENTITY,
> -- other columns,
> Rate AS PrtKey / Usage,
> PRIMARY KEY (...),
> -- other constraints,
> )
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)|||No need for further review - thanks for the help all!
"mikeb" <mike@.nohostanywhere.com> wrote in message
news:u$%23%23s$UmFHA.1412@.TK2MSFTNGP09.phx.gbl...
> Thanks Hugo.
> I couldn't agree with you more on all points - even down to the all caps
> and confusing column names (oh wait, maybe that was my own peve).
> Unfortunately, I can't change anything about the tables other than adding
> in a trigger. This database was written for another vendors software, I'm
> only augmenting it to make it work the way it should.
> And you guys are right, the zeq_# table is used to gain a unique value for
> a specific inserted column of data in a row. Again, I'd do this
> differently, probably even without use of an identity column.
> That aside, I appreciate all the comments and continued input! I'm just
> very unfamiliar with oracle sql and only at the tip of the 'berg of t-sql
> (as I continuously humble myself when reading through this NG).
> Thanks again!
> btw, here's how I converted the trigger so far -- no database yet in my
> hands to be able to test it - but can I get some input? Would be very
> nice to be able to insert it into a test database and have it work right
> from the start!! But I don't know it enough to really test the logic
> against the oracle code.
> Create Trigger WO_PrtCost ON PRTTRNI After Insert
> As
> Declare @.aNextVal int
> Declare @.PricePer float
> Begin
> If (Inserted.HISTKEY > 1)
> Begin
> SELECT @.aNextVal = Z.NEXTVAL FROM ZEQ_120 Z
> Select @.aNextVal = @.aNextVal + 1
> Select @.PricePer = Inserted.TRNCST/Inserted.PRTSISS
> Insert COSTPART
> (
> USAGE,
> PRTKEY,
> STKKEY,
> TOTCOST,
> ADDDTTM,
> ADDBY,
> COSTKEY,
> HISTKEY,
> CHRGDTTM,
> RATE
> )
> Select
> PRTSISS,
> PRTKEY,
> STKKEY,
> TRNCST,
> ADDDTTM,
> 'WO_PRTCOST TRIGGER',
> @.aNextVal,
> HISTKEY,
> ADDDTTM,
> PricePer
> From
> Inserted
> Update ZEQ_120
> Set NEXTVAL = NEXTVAL + 1
> End
> End
> --RaiseError('trigger WO_PRTCOST', 1, 1)
>
> "Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
> news:fgv4f1tf6q28otl42arm8q488m24ht2so2@.
4ax.com...
>

Wednesday, March 7, 2012

Please provide me with a solution

I am developer who codes for both front end and back end.

HEre is the situation. I have two databases sqlnts1 and sqlnts2. I need to update certain tables in sqlnts1 and then certain tables in sqlnts2 and then back to the sqlnts1 to update few more tables. This is the program logic.

When I tried executing the stored procedure written in sql server 2000 I am provided with the following message

"[OLE/DB provider returned message: Cannot start more transactions on this session.]"

To set this problem correct the only option that I have is to set xact_abort on. But, setting this option on I cannot handle the errors in code. That is this option lets the server handle the system errors.

I want to handle the errors using @.@.error programatically.

Also when I try to commit the transaction that is started before updating sqlnts1 at the end of the stored procedure it provides me with the following error.

"No transaction or savepoint of that name was found".

To work around this problem I used set xact_abort on before making updates to sqlnts2 and set it back to off after finishing updates to sqlnts2.

This way it works, but am sure given that there occurs an error in updating sqlnts2 server tables - its gonna create problems. I want to handle them by myself in the code.

Please help.

Here is the program flow. I tried beginning the distributed transaction too. Case is also checked and begin and end tran are ensured to have the same case.

Begin distributed transaction abc / begin tran abc

Update tables in sqlnts1

set xact abort on

update tables in sqlnts2

set xact abort off

Update tables in sqlnts1

commit tran / rollback tran abc

Thanks,
SubhaAre these 2 DBs on the same server or different servers?|||The sqlnts1 and 2 are two servers.

I would look forward ot hear from you.
Thanks,
Subha

Originally posted by sbaru
Are these 2 DBs on the same server or different servers?|||What is the level of nested transactions you are going into ?
find max value of @.trancount at which the error
"[OLE/DB provider returned message: Cannot start more transactions on this session.]"
occurs|||I have only one transaction on. I don't open multiple transactions.
@.trancount is only 1

Originally posted by Enigma
What is the level of nested transactions you are going into ?
find max value of @.trancount at which the error
"[OLE/DB provider returned message: Cannot start more transactions on this session.]"
occurs

Please provide me with a solution

I am developer who codes for both front end and back end.

HEre is the situation. I have two databases sqlnts1 and sqlnts2. I need to update certain tables in sqlnts1 and then certain tables in sqlnts2 and then back to the sqlnts1 to update few more tables. This is the program logic.

When I tried executing the stored procedure written in sql server 2000 I am provided with the following message

"[OLE/DB provider returned message: Cannot start more transactions on this session.]"

To set this problem correct the only option that I have is to set xact_abort on. But, setting this option on I cannot handle the errors in code. That is this option lets the server handle the system errors.

I want to handle the errors using @.@.error programatically.

Also when I try to commit the transaction that is started before updating sqlnts1 at the end of the stored procedure it provides me with the following error.

"No transaction or savepoint of that name was found".

To work around this problem I used set xact_abort on before making updates to sqlnts2 and set it back to off after finishing updates to sqlnts2.

This way it works, but am sure given that there occurs an error in updating sqlnts2 server tables - its gonna create problems. I want to handle them by myself in the code.

Please help.

Here is the program flow. I tried beginning the distributed transaction too. Case is also checked and begin and end tran are ensured to have the same case.

Begin distributed transaction abc / begin tran abc

Update tables in sqlnts1

set xact abort on

update tables in sqlnts2

set xact abort off

Update tables in sqlnts1

commit tran / rollback tran abc

Thanks,
SubhaCrosspost

http://www.dbforums.com/t970872.html (http://www.dbforums.com/t970872.html)|||I could not see any reply posted by enigma??????

Originally posted by subkrish
I am developer who codes for both front end and back end.

HEre is the situation. I have two databases sqlnts1 and sqlnts2. I need to update certain tables in sqlnts1 and then certain tables in sqlnts2 and then back to the sqlnts1 to update few more tables. This is the program logic.

When I tried executing the stored procedure written in sql server 2000 I am provided with the following message

"[OLE/DB provider returned message: Cannot start more transactions on this session.]"

To set this problem correct the only option that I have is to set xact_abort on. But, setting this option on I cannot handle the errors in code. That is this option lets the server handle the system errors.

I want to handle the errors using @.@.error programatically.

Also when I try to commit the transaction that is started before updating sqlnts1 at the end of the stored procedure it provides me with the following error.

"No transaction or savepoint of that name was found".

To work around this problem I used set xact_abort on before making updates to sqlnts2 and set it back to off after finishing updates to sqlnts2.

This way it works, but am sure given that there occurs an error in updating sqlnts2 server tables - its gonna create problems. I want to handle them by myself in the code.

Please help.

Here is the program flow. I tried beginning the distributed transaction too. Case is also checked and begin and end tran are ensured to have the same case.

Begin distributed transaction abc / begin tran abc

Update tables in sqlnts1

set xact abort on

update tables in sqlnts2

set xact abort off

Update tables in sqlnts1

commit tran / rollback tran abc

Thanks,
Subha