Showing posts with label update. Show all posts
Showing posts with label update. Show all posts

Friday, March 30, 2012

mssql 2000 update from select

I am trying to update a table from a select statement, any suggestions?

update (select column1 from table1)
set column2 = 'value'

The data in column1 contains the name of the table I want to update column2 with the 'value'.

I'm am pretty sure the syntax is in correct along with the structure. The error...

Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near '('.
Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near '='.

Quote:

Originally Posted by tdority

I am trying to update a table from a select statement, any suggestions?

update (select column1 from table1)
set column2 = 'value'

The data in column1 contains the name of the table I want to update column2 with the 'value'.

I'm am pretty sure the syntax is in correct along with the structure. The error...

Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near '('.
Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near '='.


nope, the syntax is not correct. in this case you have to build the string for the entire update command..

set @.sqlcmd = 'update ..."

exec (@.sqlcmd)|||Please explain how to build.

Wednesday, March 28, 2012

Ms-sql

Hi
We have a MS-SQL dB that is more than 300 gb and have some performance problems.
One of the problems is, that the system do not automatically update statistics.
In the test system, which is a copy of production we have run sp_updatestats and all the tables and index is updated but when we run sp_updatestats in production, it return normally after one hour but it do not update all tables and index ??
Regards
JohnAre you running this at a time frame that sql server is the least utilized (like between midnight and 4 a.m. - depending on your business model) ? Also, what is the output generated when you run sp_updatestats ? How do you know that it is not updating the statistics for all tables ?|||Hi
The sp_updatestats was running Saturday, while the system performance is low.
The output was statistics for all tables have been updated

The application (SAP), have some dB information reports and it is possible to get information on tables and index. In the test system SAP reports, that the statistics is updated but not in the production.

When I make the following sql in the production and in the test system:

select * from sysobjects so, sysindexes si where so.name = 'KNA1' and si.name like 'KNA1% Z'

I can see, that the number in the rows column is zero. I expect that the number is different from zero.

Monday, March 26, 2012

MSRepl_Commands question

SORRY FOR THE LONG POST.
I am using transactional replication. I have an update process that is
run by users (not dbas). The update process among many other things
will delete replication, perform updates, and then reinstall
replication. This process has been working great for us (in testing).
However, there are times when the distribution agent hasn't finished
processing all the rows in msrepl_commands and the replication gets
dropped which causes lost (not replicated) commands.
We started by just running sp_browereplcmds with the proper
publication_database_id value to see if any commands were outstanding.
The thought was to check the recordset, if empty, then proceed, else
wait, until specified time then cancel the update with a nice message
about waiting until replication was complete. Great, right? Wrong.
Even after replication is finished and EVEN after the cleanup agent is
run (we are considering running it manually and rechecking the list),
there are commands STILL in the table. They all have command type
values of -2147xxxx and they all appear to be snapshot commands.
Sorry for the long post, but here's the question: Does anyone know
where I can find a key to these values? I would like to just ignore any
-2147xxxx type command in the table and proceed with dropping
replication.
Any help would be appreciated!
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
this is as near as I can figure
-2147483641 directory check
-2147483598 file check
-2147483597 unknown
-2147483646 apply schema
-2147483646 apply index
-2147483645 sync command
-2147483596 unknown
Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html
"PBarbin" <pbarbin@.nospam.com> wrote in message
news:%23lDmE10aEHA.2516@.TK2MSFTNGP10.phx.gbl...
> SORRY FOR THE LONG POST.
> I am using transactional replication. I have an update process that is
> run by users (not dbas). The update process among many other things
> will delete replication, perform updates, and then reinstall
> replication. This process has been working great for us (in testing).
> However, there are times when the distribution agent hasn't finished
> processing all the rows in msrepl_commands and the replication gets
> dropped which causes lost (not replicated) commands.
> We started by just running sp_browereplcmds with the proper
> publication_database_id value to see if any commands were outstanding.
> The thought was to check the recordset, if empty, then proceed, else
> wait, until specified time then cancel the update with a nice message
> about waiting until replication was complete. Great, right? Wrong.
> Even after replication is finished and EVEN after the cleanup agent is
> run (we are considering running it manually and rechecking the list),
> there are commands STILL in the table. They all have command type
> values of -2147xxxx and they all appear to be snapshot commands.
> Sorry for the long post, but here's the question: Does anyone know
> where I can find a key to these values? I would like to just ignore any
> -2147xxxx type command in the table and proceed with dropping
> replication.
> Any help would be appreciated!
> *** Sent via Developersdex http://www.codecomments.com ***
> Don't just participate in USENET...get rewarded for it!
|||Thanks for the reply. As far as I can tell, transactional replication
commands are of type 30.
As an alternate question, can anyone think of a way that I can be SURE
that transactional replication is finished before deleting it and
readding?
Paul
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
|||Paul,
you could compare the xact_seqno in MSDistribution_history (last processed
transaction sequence number) to the values in msrepl_commands. Presumably,
if the last row in each table has the same xact_seqno (after reformatting
slightly), then you're ok.
HTH,
Paul Ibison
|||Paul, that may help tremendously! I'll look into it. Have you noticed
that sp_browsereplcmds shows commands even when there are none to be
processed. I was hoping it was just because we were in a test
environment and we weren't always playing by the rules, but I didn't
want to ship this to all customers without being pretty confident that
my solution would work. I'll try this get back...
Thanks.
Paul
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
|||Background
When my program is updated in the future, the first step will be to
delete the transactional replication, make all database changes to the
publisher and the subscriber and then reinitialize replication. We want
to make sure that the distribution agent has finished processing all
outstanding transactions before dropping it.
Problem
We considered checking the status of the distribution agent but realized
that we couldn't. One reason is that it never "finishes". This agent
runs continuously. Also, its possible to have the status of the agent
as "Idle" even when there are commands left to be processed (this
process is asynchronous).
So, we decided to query the system table, MSRepl_Commands, directly.
This table has a few interesting problems. One is that commands are not
dropped immediately after being processed by replication. Another is
that rows exist in this table for both snapshot and transactional
replication. As usual, the only identifier to distinguish them was not
documented and we were not completely sure which rows to filter. The
stored procedure that Microsoft recommends using doesn't take these
items into consideration and will return rows when transactional
replication is "finished".
Solution
Profiling the agent gave us all the information we needed. We found
that the subscription database contains a table that tracks the last
transaction number processed for each distribution agent that hits the
database (we only have 1). Now we can filter out all the old commands
by checking their transaction number against this value. Also, we saw
that one of the stored procedures defines a snapshot bit (0x80000000)
and uses a bitwise AND on this undocumented "Type" column to see which
commands are snapshot and which are not. Using both of these pieces of
info, we are able to query the table to accurately determine the status
of transactional replication.
Hope this helps somebody. I find it amazing how little documentation
exists regarding replication. If it weren't for the great posters (Paul
I. and Hilary C) on this group, a LOT of us would be in trouble.
Thanks!
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!

MSRepl_Commands

Hi everyone
has anyone come across / developed a way of transforming the commands
in MSRepl_Commands so that, for instance, and Update becomes a Delete
or Insert?
thanks in adveance for abny assists!
Are you requiring an explanation of how this occurs in replication?
If so, this is referred to as a deferred update - see
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q302/3/41.ASP&NoWebContent=1
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com .
|||MS_replcommands is a queue. You can modify this queue to delete commands.
Modifying them is difficult as they are in binary. Your best bet is to
ensure that your updates are not replaced by an insert delete pair.
Please refer to the following kb articles for more information.
http://support.microsoft.com/default.aspx/kb/302341
and
http://support.microsoft.com/kb/238254
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"RedCamel" <RichardJGilbert@.hotmail.com> wrote in message
news:1163426512.098950.159840@.m73g2000cwd.googlegr oups.com...
> Hi everyone
> has anyone come across / developed a way of transforming the commands
> in MSRepl_Commands so that, for instance, and Update becomes a Delete
> or Insert?
> thanks in adveance for abny assists!
>

Friday, March 23, 2012

MSQL Update

Hi
Can anyone help me with the MSSQL following problem:
I want to update the field "Date" with today´s date in a Tabel named Customers
I want to click on a "button" that runs something like:

Update Date with Today´s date where CustomerName = TextBox.text

Thanks in advance for your helpstring strSQL = "UPDATE [Customers] SET [Date] = GetDate() WHERE CustomerName = " + TextBox.Text

basic, basic, basic

Wednesday, March 21, 2012

msg16915

When I want to make an update on a table which make a trigger action, it
gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
already exist"
Can anyone please give me more info on msg 16915 or how to solve it? Thanks.Possibly the trigger creates a cursor without deallocating it. Check the trigger code.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
""Allen Iverson"" <no_spam@.bk.com> wrote in message news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
> When I want to make an update on a table which make a trigger action, it
> gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
> already exist"
> Can anyone please give me more info on msg 16915 or how to solve it? Thanks.
>|||In fact, this is the code, can anyone help:
if exists (select id from sysobjects where name = 'apple.A4000_ins_upd_trg'
and
type = 'TR')
begin
drop trigger apple.A4000_ins_upd_trg
print 'A4000_ins_upd_trg is dropped.'
end
go
create trigger apple.A4000_ins_upd_trg on apple.APRN4000
for update, insert
as
declare @.schoolyear varchar(1),
@.UNID varchar(20),
@.OBJECT_TYPE char(1),
@.SCHOOLNUM varchar(3),
@.STULINK numeric(5),
@.SEQUENCE numeric(5),
@.STATUS char(1),
@.RELATION varchar(2),
@.LASTNAME varchar(20),
@.FIRSTNAME varchar(20),
@.MIDDLENAME varchar(13),
@.SALUTATION varchar(4),
@.EMPLOYER varchar(40),
@.OCCUPATION varchar(30),
@.WRKTEL numeric(9),
@.WRKEXTN varchar(4),
@.ALTTEL numeric(9),
@.TELEPHONE numeric(9),
@.USERSTAMP varchar(10),
@.PERMNUM varchar(12),
@.GRADE varchar(2),
@.FAMILYNUM numeric(5),
@.ADDRESS1 varchar(50),
@.ADDRESS2 varchar(40),
@.AREA varchar(30),
@.TERRITORY varchar(25),
@.FAXNO varchar(11),
@.ATTENTION varchar(30),
@.REFCODE varchar(30),
@.counter int,
@.rec_count_before int,
@.rec_count_after int
-- initialization
select @.schoolyear = '4'
select @.counter = 1
-- count how many records in inserted table
select @.rec_count_after = count(STULINK)
from inserted
-- count how many records in before table
select @.rec_count_before = count(STULINK)
from deleted
-- define cursor
declare inserted_curs cursor for
select SCHOOLNUM,
STULINK,
SEQUENCE,
STATUS,
RELATION,
LASTNAME,
FIRSTNAME,
MIDDLENAME,
SALUTATION,
EMPLOYER,
OCCUPATION,
WRKTEL,
WRKEXTN,
ALTTEL,
TELEPHONE
from inserted
open inserted_curs
fetch inserted_curs
into @.SCHOOLNUM,
@.STULINK,
@.SEQUENCE,
@.STATUS,
@.RELATION,
@.LASTNAME,
@.FIRSTNAME,
@.MIDDLENAME,
@.SALUTATION,
@.EMPLOYER,
@.OCCUPATION,
@.WRKTEL,
@.WRKEXTN,
@.ALTTEL,
@.TELEPHONE
if @.rec_count_before = 0
-- insert action
begin
print 'insert action'
print @.STULINK
print @.sequence
insert into dbo.EAI_ADM_PARENT
(STULINK,
SEQUENCE)
VALUES
(@.STULINK,
@.SEQUENCE)
end
else
-- update action
-- we can assume the record exists in EAI_A4000
begin
print 'update action start'
while @.counter <= @.rec_count_after
begin
update dbo.EAI_ADM_PARENT
set STATUS = @.STATUS,
RELATION = @.RELATION,
LASTNAME = @.LASTNAME,
FIRSTNAME = @.FIRSTNAME,
MIDDLENAME = @.MIDDLENAME,
SALUTATION = @.SALUTATION,
EMPLOYER = @.EMPLOYER,
OCCUPATION = @.OCCUPATION,
WRKTEL = @.WRKTEL,
WRKEXTN = @.WRKEXTN,
ALTTEL = @.ALTTEL,
TELEPHONE = @.TELEPHONE
from apple.APRN4000 P
where P.STULINK = @.STULINK
and P.SEQUENCE = @.SEQUENCE
-- get next record
select @.counter = @.counter + 1
if @.counter <= @.rec_count_after
begin
fetch inserted_curs
into @.SCHOOLNUM,
@.STULINK,
@.SEQUENCE,
@.STATUS,
@.RELATION,
@.LASTNAME,
@.FIRSTNAME,
@.MIDDLENAME,
@.SALUTATION,
@.EMPLOYER,
@.OCCUPATION,
@.WRKTEL,
@.WRKEXTN,
@.ALTTEL,
@.TELEPHONE
end
end
end
-- ending session
close inserted_curs
deallocate inserted_curs
print 'successful'
go
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:Oo3U0$D2EHA.3708@.TK2MSFTNGP14.phx.gbl...
> Possibly the trigger creates a cursor without deallocating it. Check the
> trigger code.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
> news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
>> When I want to make an update on a table which make a trigger action, it
>> gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
>> already exist"
>> Can anyone please give me more info on msg 16915 or how to solve it?
>> Thanks.
>>
>|||Where can I check the message meaning?
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:Oo3U0$D2EHA.3708@.TK2MSFTNGP14.phx.gbl...
> Possibly the trigger creates a cursor without deallocating it. Check the
> trigger code.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
> news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
>> When I want to make an update on a table which make a trigger action, it
>> gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
>> already exist"
>> Can anyone please give me more info on msg 16915 or how to solve it?
>> Thanks.
>>
>|||Can any one please help? Thanks.
""Allen Iverson"" <no_spam@.bk.com> wrote in message
news:Oa5t1LE2EHA.1408@.TK2MSFTNGP10.phx.gbl...
> In fact, this is the code, can anyone help:
>
> if exists (select id from sysobjects where name => 'apple.A4000_ins_upd_trg' and
> type = 'TR')
> begin
> drop trigger apple.A4000_ins_upd_trg
> print 'A4000_ins_upd_trg is dropped.'
> end
> go
> create trigger apple.A4000_ins_upd_trg on apple.APRN4000
> for update, insert
> as
> declare @.schoolyear varchar(1),
> @.UNID varchar(20),
> @.OBJECT_TYPE char(1),
> @.SCHOOLNUM varchar(3),
> @.STULINK numeric(5),
> @.SEQUENCE numeric(5),
> @.STATUS char(1),
> @.RELATION varchar(2),
> @.LASTNAME varchar(20),
> @.FIRSTNAME varchar(20),
> @.MIDDLENAME varchar(13),
> @.SALUTATION varchar(4),
> @.EMPLOYER varchar(40),
> @.OCCUPATION varchar(30),
> @.WRKTEL numeric(9),
> @.WRKEXTN varchar(4),
> @.ALTTEL numeric(9),
> @.TELEPHONE numeric(9),
> @.USERSTAMP varchar(10),
> @.PERMNUM varchar(12),
> @.GRADE varchar(2),
> @.FAMILYNUM numeric(5),
> @.ADDRESS1 varchar(50),
> @.ADDRESS2 varchar(40),
> @.AREA varchar(30),
> @.TERRITORY varchar(25),
> @.FAXNO varchar(11),
> @.ATTENTION varchar(30),
> @.REFCODE varchar(30),
> @.counter int,
> @.rec_count_before int,
> @.rec_count_after int
>
> -- initialization
> select @.schoolyear = '4'
> select @.counter = 1
>
> -- count how many records in inserted table
> select @.rec_count_after = count(STULINK)
> from inserted
> -- count how many records in before table
> select @.rec_count_before = count(STULINK)
> from deleted
>
> -- define cursor
> declare inserted_curs cursor for
> select SCHOOLNUM,
> STULINK,
> SEQUENCE,
> STATUS,
> RELATION,
> LASTNAME,
> FIRSTNAME,
> MIDDLENAME,
> SALUTATION,
> EMPLOYER,
> OCCUPATION,
> WRKTEL,
> WRKEXTN,
> ALTTEL,
> TELEPHONE
> from inserted
> open inserted_curs
> fetch inserted_curs
> into @.SCHOOLNUM,
> @.STULINK,
> @.SEQUENCE,
> @.STATUS,
> @.RELATION,
> @.LASTNAME,
> @.FIRSTNAME,
> @.MIDDLENAME,
> @.SALUTATION,
> @.EMPLOYER,
> @.OCCUPATION,
> @.WRKTEL,
> @.WRKEXTN,
> @.ALTTEL,
> @.TELEPHONE
> if @.rec_count_before = 0
> -- insert action
> begin
> print 'insert action'
> print @.STULINK
> print @.sequence
> insert into dbo.EAI_ADM_PARENT
> (STULINK,
> SEQUENCE)
> VALUES
> (@.STULINK,
> @.SEQUENCE)
> end
> else
> -- update action
> -- we can assume the record exists in EAI_A4000
> begin
> print 'update action start'
> while @.counter <= @.rec_count_after
> begin
> update dbo.EAI_ADM_PARENT
> set STATUS = @.STATUS,
> RELATION = @.RELATION,
> LASTNAME = @.LASTNAME,
> FIRSTNAME = @.FIRSTNAME,
> MIDDLENAME = @.MIDDLENAME,
> SALUTATION = @.SALUTATION,
> EMPLOYER = @.EMPLOYER,
> OCCUPATION = @.OCCUPATION,
> WRKTEL = @.WRKTEL,
> WRKEXTN = @.WRKEXTN,
> ALTTEL = @.ALTTEL,
> TELEPHONE = @.TELEPHONE
> from apple.APRN4000 P
> where P.STULINK = @.STULINK
> and P.SEQUENCE = @.SEQUENCE
> -- get next record
> select @.counter = @.counter + 1
> if @.counter <= @.rec_count_after
> begin
> fetch inserted_curs
> into @.SCHOOLNUM,
> @.STULINK,
> @.SEQUENCE,
> @.STATUS,
> @.RELATION,
> @.LASTNAME,
> @.FIRSTNAME,
> @.MIDDLENAME,
> @.SALUTATION,
> @.EMPLOYER,
> @.OCCUPATION,
> @.WRKTEL,
> @.WRKEXTN,
> @.ALTTEL,
> @.TELEPHONE
> end
> end
> end
>
> -- ending session
> close inserted_curs
> deallocate inserted_curs
> print 'successful'
> go
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote
> in message news:Oo3U0$D2EHA.3708@.TK2MSFTNGP14.phx.gbl...
>> Possibly the trigger creates a cursor without deallocating it. Check the
>> trigger code.
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://www.solidqualitylearning.com/
>>
>> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
>> news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
>> When I want to make an update on a table which make a trigger action, it
>> gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
>> already exist"
>> Can anyone please give me more info on msg 16915 or how to solve it?
>> Thanks.
>>
>>
>|||Actually, I doubt I found the cause of error.
Here is situation. I define trigger A in table TB1 and trigger B in table
TB2. The change in record in TB1 make trigger A act in which write record to
TB2 and make trigger B act in which write record to TB3. Much like a chain.
But then when I make change in TB1, I got error message saying cursor
already exists. Can anyone please help? Thanks.
""Allen Iverson"" <no_spam@.bk.com> wrote in message
news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
> When I want to make an update on a table which make a trigger action, it
> gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
> already exist"
> Can anyone please give me more info on msg 16915 or how to solve it?
> Thanks.
>|||Perhaps the inner trigger creates a cursor with the same name as already was created by the outer
trigger?
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
""Allen Iverson"" <no_spam@.bk.com> wrote in message news:O1NItpQ2EHA.3324@.tk2msftngp13.phx.gbl...
> Actually, I doubt I found the cause of error.
> Here is situation. I define trigger A in table TB1 and trigger B in table
> TB2. The change in record in TB1 make trigger A act in which write record to
> TB2 and make trigger B act in which write record to TB3. Much like a chain.
> But then when I make change in TB1, I got error message saying cursor
> already exists. Can anyone please help? Thanks.
>
> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
> news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
> > When I want to make an update on a table which make a trigger action, it
> > gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
> > already exist"
> >
> > Can anyone please give me more info on msg 16915 or how to solve it?
> > Thanks.
> >
>|||Can anyone please help?
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:usqoWuQ2EHA.1152@.TK2MSFTNGP14.phx.gbl...
> Perhaps the inner trigger creates a cursor with the same name as already
> was created by the outer
> trigger?
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
> news:O1NItpQ2EHA.3324@.tk2msftngp13.phx.gbl...
>> Actually, I doubt I found the cause of error.
>> Here is situation. I define trigger A in table TB1 and trigger B in table
>> TB2. The change in record in TB1 make trigger A act in which write record
>> to
>> TB2 and make trigger B act in which write record to TB3. Much like a
>> chain.
>> But then when I make change in TB1, I got error message saying cursor
>> already exists. Can anyone please help? Thanks.
>>
>> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
>> news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
>> > When I want to make an update on a table which make a trigger action,
>> > it
>> > gives me error "msg16915, level 16, State 1, Procedure ..." and
>> > "cursor
>> > already exist"
>> >
>> > Can anyone please give me more info on msg 16915 or how to solve it?
>> > Thanks.
>> >
>>
>|||You've got more problems with this trigger than just that error.
First of all, you have some serious logic bugs and some flawed usage.
1. Try to avoid cursors always, but especially inside of a trigger.
2. The INSERTED and DELETED tables will only store rows that were modified.
If Inserts, DELETED will be NULL; if Update, INSERTED and DELETED will
contain the same records; if Delete, INSERTED will be NULL. Neither of
these will have the same count as the base table unless this is the first
statement executed against the base table or was applied to the entire
table.
3. If you do use a cursor, you need to either code a GLOBAL CURSOR, and need
to check for its existence before you create it or use TEMPORARY cursors,
LOCAL.
4. The logic was a little conveluted; so, I'm not sure what the intent of
the trigger is but you could have simplified the code dramatically by using
constraints to handle most of this and then only using set-based statements
within the trigger for the specialized rules.
5. The error message you are getting is due to the trigger firing more than
once simultaneously due to concurrent users. The cursor already exists when
the second, or n th firing occurs.
Sincerely,
Anthony Thomas
""Allen Iverson"" <no_spam@.bk.com> wrote in message
news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
When I want to make an update on a table which make a trigger action, it
gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
already exist"
Can anyone please give me more info on msg 16915 or how to solve it? Thanks.

msg16915

When I want to make an update on a table which make a trigger action, it
gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
already exist"
Can anyone please give me more info on msg 16915 or how to solve it? Thanks.
Possibly the trigger creates a cursor without deallocating it. Check the trigger code.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
""Allen Iverson"" <no_spam@.bk.com> wrote in message news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
> When I want to make an update on a table which make a trigger action, it
> gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
> already exist"
> Can anyone please give me more info on msg 16915 or how to solve it? Thanks.
>
|||In fact, this is the code, can anyone help:
if exists (select id from sysobjects where name = 'apple.A4000_ins_upd_trg'
and
type = 'TR')
begin
drop trigger apple.A4000_ins_upd_trg
print 'A4000_ins_upd_trg is dropped.'
end
go
create trigger apple.A4000_ins_upd_trg on apple.APRN4000
for update, insert
as
declare @.schoolyear varchar(1),
@.UNID varchar(20),
@.OBJECT_TYPE char(1),
@.SCHOOLNUM varchar(3),
@.STULINK numeric(5),
@.SEQUENCE numeric(5),
@.STATUS char(1),
@.RELATION varchar(2),
@.LASTNAME varchar(20),
@.FIRSTNAME varchar(20),
@.MIDDLENAME varchar(13),
@.SALUTATION varchar(4),
@.EMPLOYER varchar(40),
@.OCCUPATION varchar(30),
@.WRKTEL numeric(9),
@.WRKEXTN varchar(4),
@.ALTTEL numeric(9),
@.TELEPHONE numeric(9),
@.USERSTAMP varchar(10),
@.PERMNUM varchar(12),
@.GRADE varchar(2),
@.FAMILYNUM numeric(5),
@.ADDRESS1 varchar(50),
@.ADDRESS2 varchar(40),
@.AREA varchar(30),
@.TERRITORY varchar(25),
@.FAXNO varchar(11),
@.ATTENTION varchar(30),
@.REFCODE varchar(30),
@.counter int,
@.rec_count_before int,
@.rec_count_after int
-- initialization
select @.schoolyear = '4'
select @.counter = 1
-- count how many records in inserted table
select @.rec_count_after = count(STULINK)
from inserted
-- count how many records in before table
select @.rec_count_before = count(STULINK)
from deleted
-- define cursor
declare inserted_curs cursor for
select SCHOOLNUM,
STULINK,
SEQUENCE,
STATUS,
RELATION,
LASTNAME,
FIRSTNAME,
MIDDLENAME,
SALUTATION,
EMPLOYER,
OCCUPATION,
WRKTEL,
WRKEXTN,
ALTTEL,
TELEPHONE
from inserted
open inserted_curs
fetch inserted_curs
into @.SCHOOLNUM,
@.STULINK,
@.SEQUENCE,
@.STATUS,
@.RELATION,
@.LASTNAME,
@.FIRSTNAME,
@.MIDDLENAME,
@.SALUTATION,
@.EMPLOYER,
@.OCCUPATION,
@.WRKTEL,
@.WRKEXTN,
@.ALTTEL,
@.TELEPHONE
if @.rec_count_before = 0
-- insert action
begin
print 'insert action'
print @.STULINK
print @.sequence
insert into dbo.EAI_ADM_PARENT
(STULINK,
SEQUENCE)
VALUES
(@.STULINK,
@.SEQUENCE)
end
else
-- update action
-- we can assume the record exists in EAI_A4000
begin
print 'update action start'
while @.counter <= @.rec_count_after
begin
update dbo.EAI_ADM_PARENT
set STATUS = @.STATUS,
RELATION = @.RELATION,
LASTNAME = @.LASTNAME,
FIRSTNAME = @.FIRSTNAME,
MIDDLENAME = @.MIDDLENAME,
SALUTATION = @.SALUTATION,
EMPLOYER = @.EMPLOYER,
OCCUPATION = @.OCCUPATION,
WRKTEL = @.WRKTEL,
WRKEXTN = @.WRKEXTN,
ALTTEL = @.ALTTEL,
TELEPHONE = @.TELEPHONE
from apple.APRN4000 P
where P.STULINK = @.STULINK
and P.SEQUENCE = @.SEQUENCE
-- get next record
select @.counter = @.counter + 1
if @.counter <= @.rec_count_after
begin
fetch inserted_curs
into @.SCHOOLNUM,
@.STULINK,
@.SEQUENCE,
@.STATUS,
@.RELATION,
@.LASTNAME,
@.FIRSTNAME,
@.MIDDLENAME,
@.SALUTATION,
@.EMPLOYER,
@.OCCUPATION,
@.WRKTEL,
@.WRKEXTN,
@.ALTTEL,
@.TELEPHONE
end
end
end
-- ending session
close inserted_curs
deallocate inserted_curs
print 'successful'
go
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:Oo3U0$D2EHA.3708@.TK2MSFTNGP14.phx.gbl...
> Possibly the trigger creates a cursor without deallocating it. Check the
> trigger code.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
> news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
>
|||Where can I check the message meaning?
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:Oo3U0$D2EHA.3708@.TK2MSFTNGP14.phx.gbl...
> Possibly the trigger creates a cursor without deallocating it. Check the
> trigger code.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
> news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
>
|||Can any one please help? Thanks.
""Allen Iverson"" <no_spam@.bk.com> wrote in message
news:Oa5t1LE2EHA.1408@.TK2MSFTNGP10.phx.gbl...
> In fact, this is the code, can anyone help:
>
> if exists (select id from sysobjects where name =
> 'apple.A4000_ins_upd_trg' and
> type = 'TR')
> begin
> drop trigger apple.A4000_ins_upd_trg
> print 'A4000_ins_upd_trg is dropped.'
> end
> go
> create trigger apple.A4000_ins_upd_trg on apple.APRN4000
> for update, insert
> as
> declare @.schoolyear varchar(1),
> @.UNID varchar(20),
> @.OBJECT_TYPE char(1),
> @.SCHOOLNUM varchar(3),
> @.STULINK numeric(5),
> @.SEQUENCE numeric(5),
> @.STATUS char(1),
> @.RELATION varchar(2),
> @.LASTNAME varchar(20),
> @.FIRSTNAME varchar(20),
> @.MIDDLENAME varchar(13),
> @.SALUTATION varchar(4),
> @.EMPLOYER varchar(40),
> @.OCCUPATION varchar(30),
> @.WRKTEL numeric(9),
> @.WRKEXTN varchar(4),
> @.ALTTEL numeric(9),
> @.TELEPHONE numeric(9),
> @.USERSTAMP varchar(10),
> @.PERMNUM varchar(12),
> @.GRADE varchar(2),
> @.FAMILYNUM numeric(5),
> @.ADDRESS1 varchar(50),
> @.ADDRESS2 varchar(40),
> @.AREA varchar(30),
> @.TERRITORY varchar(25),
> @.FAXNO varchar(11),
> @.ATTENTION varchar(30),
> @.REFCODE varchar(30),
> @.counter int,
> @.rec_count_before int,
> @.rec_count_after int
>
> -- initialization
> select @.schoolyear = '4'
> select @.counter = 1
>
> -- count how many records in inserted table
> select @.rec_count_after = count(STULINK)
> from inserted
> -- count how many records in before table
> select @.rec_count_before = count(STULINK)
> from deleted
>
> -- define cursor
> declare inserted_curs cursor for
> select SCHOOLNUM,
> STULINK,
> SEQUENCE,
> STATUS,
> RELATION,
> LASTNAME,
> FIRSTNAME,
> MIDDLENAME,
> SALUTATION,
> EMPLOYER,
> OCCUPATION,
> WRKTEL,
> WRKEXTN,
> ALTTEL,
> TELEPHONE
> from inserted
> open inserted_curs
> fetch inserted_curs
> into @.SCHOOLNUM,
> @.STULINK,
> @.SEQUENCE,
> @.STATUS,
> @.RELATION,
> @.LASTNAME,
> @.FIRSTNAME,
> @.MIDDLENAME,
> @.SALUTATION,
> @.EMPLOYER,
> @.OCCUPATION,
> @.WRKTEL,
> @.WRKEXTN,
> @.ALTTEL,
> @.TELEPHONE
> if @.rec_count_before = 0
> -- insert action
> begin
> print 'insert action'
> print @.STULINK
> print @.sequence
> insert into dbo.EAI_ADM_PARENT
> (STULINK,
> SEQUENCE)
> VALUES
> (@.STULINK,
> @.SEQUENCE)
> end
> else
> -- update action
> -- we can assume the record exists in EAI_A4000
> begin
> print 'update action start'
> while @.counter <= @.rec_count_after
> begin
> update dbo.EAI_ADM_PARENT
> set STATUS = @.STATUS,
> RELATION = @.RELATION,
> LASTNAME = @.LASTNAME,
> FIRSTNAME = @.FIRSTNAME,
> MIDDLENAME = @.MIDDLENAME,
> SALUTATION = @.SALUTATION,
> EMPLOYER = @.EMPLOYER,
> OCCUPATION = @.OCCUPATION,
> WRKTEL = @.WRKTEL,
> WRKEXTN = @.WRKEXTN,
> ALTTEL = @.ALTTEL,
> TELEPHONE = @.TELEPHONE
> from apple.APRN4000 P
> where P.STULINK = @.STULINK
> and P.SEQUENCE = @.SEQUENCE
> -- get next record
> select @.counter = @.counter + 1
> if @.counter <= @.rec_count_after
> begin
> fetch inserted_curs
> into @.SCHOOLNUM,
> @.STULINK,
> @.SEQUENCE,
> @.STATUS,
> @.RELATION,
> @.LASTNAME,
> @.FIRSTNAME,
> @.MIDDLENAME,
> @.SALUTATION,
> @.EMPLOYER,
> @.OCCUPATION,
> @.WRKTEL,
> @.WRKEXTN,
> @.ALTTEL,
> @.TELEPHONE
> end
> end
> end
>
> -- ending session
> close inserted_curs
> deallocate inserted_curs
> print 'successful'
> go
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote
> in message news:Oo3U0$D2EHA.3708@.TK2MSFTNGP14.phx.gbl...
>
|||Actually, I doubt I found the cause of error.
Here is situation. I define trigger A in table TB1 and trigger B in table
TB2. The change in record in TB1 make trigger A act in which write record to
TB2 and make trigger B act in which write record to TB3. Much like a chain.
But then when I make change in TB1, I got error message saying cursor
already exists. Can anyone please help? Thanks.
""Allen Iverson"" <no_spam@.bk.com> wrote in message
news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
> When I want to make an update on a table which make a trigger action, it
> gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
> already exist"
> Can anyone please give me more info on msg 16915 or how to solve it?
> Thanks.
>
|||Perhaps the inner trigger creates a cursor with the same name as already was created by the outer
trigger?
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
""Allen Iverson"" <no_spam@.bk.com> wrote in message news:O1NItpQ2EHA.3324@.tk2msftngp13.phx.gbl...
> Actually, I doubt I found the cause of error.
> Here is situation. I define trigger A in table TB1 and trigger B in table
> TB2. The change in record in TB1 make trigger A act in which write record to
> TB2 and make trigger B act in which write record to TB3. Much like a chain.
> But then when I make change in TB1, I got error message saying cursor
> already exists. Can anyone please help? Thanks.
>
> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
> news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
>
|||Can anyone please help?
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:usqoWuQ2EHA.1152@.TK2MSFTNGP14.phx.gbl...
> Perhaps the inner trigger creates a cursor with the same name as already
> was created by the outer
> trigger?
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
> news:O1NItpQ2EHA.3324@.tk2msftngp13.phx.gbl...
>
|||You've got more problems with this trigger than just that error.
First of all, you have some serious logic bugs and some flawed usage.
1. Try to avoid cursors always, but especially inside of a trigger.
2. The INSERTED and DELETED tables will only store rows that were modified.
If Inserts, DELETED will be NULL; if Update, INSERTED and DELETED will
contain the same records; if Delete, INSERTED will be NULL. Neither of
these will have the same count as the base table unless this is the first
statement executed against the base table or was applied to the entire
table.
3. If you do use a cursor, you need to either code a GLOBAL CURSOR, and need
to check for its existence before you create it or use TEMPORARY cursors,
LOCAL.
4. The logic was a little conveluted; so, I'm not sure what the intent of
the trigger is but you could have simplified the code dramatically by using
constraints to handle most of this and then only using set-based statements
within the trigger for the specialized rules.
5. The error message you are getting is due to the trigger firing more than
once simultaneously due to concurrent users. The cursor already exists when
the second, or n th firing occurs.
Sincerely,
Anthony Thomas

""Allen Iverson"" <no_spam@.bk.com> wrote in message
news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
When I want to make an update on a table which make a trigger action, it
gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
already exist"
Can anyone please give me more info on msg 16915 or how to solve it? Thanks.

msg16915

When I want to make an update on a table which make a trigger action, it
gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
already exist"
Can anyone please give me more info on msg 16915 or how to solve it? Thanks.Possibly the trigger creates a cursor without deallocating it. Check the tri
gger code.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
""Allen Iverson"" <no_spam@.bk.com> wrote in message news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx
.gbl...
> When I want to make an update on a table which make a trigger action, it
> gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
> already exist"
> Can anyone please give me more info on msg 16915 or how to solve it? Thank
s.
>|||In fact, this is the code, can anyone help:
if exists (select id from sysobjects where name = 'apple.A4000_ins_upd_trg'
and
type = 'TR')
begin
drop trigger apple.A4000_ins_upd_trg
print 'A4000_ins_upd_trg is dropped.'
end
go
create trigger apple.A4000_ins_upd_trg on apple.APRN4000
for update, insert
as
declare @.schoolyear varchar(1),
@.UNID varchar(20),
@.OBJECT_TYPE char(1),
@.SCHOOLNUM varchar(3),
@.STULINK numeric(5),
@.SEQUENCE numeric(5),
@.STATUS char(1),
@.RELATION varchar(2),
@.LASTNAME varchar(20),
@.FIRSTNAME varchar(20),
@.MIDDLENAME varchar(13),
@.SALUTATION varchar(4),
@.EMPLOYER varchar(40),
@.OCCUPATION varchar(30),
@.WRKTEL numeric(9),
@.WRKEXTN varchar(4),
@.ALTTEL numeric(9),
@.TELEPHONE numeric(9),
@.USERSTAMP varchar(10),
@.PERMNUM varchar(12),
@.GRADE varchar(2),
@.FAMILYNUM numeric(5),
@.ADDRESS1 varchar(50),
@.ADDRESS2 varchar(40),
@.AREA varchar(30),
@.TERRITORY varchar(25),
@.FAXNO varchar(11),
@.ATTENTION varchar(30),
@.REFCODE varchar(30),
@.counter int,
@.rec_count_before int,
@.rec_count_after int
-- initialization
select @.schoolyear = '4'
select @.counter = 1
-- count how many records in inserted table
select @.rec_count_after = count(STULINK)
from inserted
-- count how many records in before table
select @.rec_count_before = count(STULINK)
from deleted
-- define cursor
declare inserted_curs cursor for
select SCHOOLNUM,
STULINK,
SEQUENCE,
STATUS,
RELATION,
LASTNAME,
FIRSTNAME,
MIDDLENAME,
SALUTATION,
EMPLOYER,
OCCUPATION,
WRKTEL,
WRKEXTN,
ALTTEL,
TELEPHONE
from inserted
open inserted_curs
fetch inserted_curs
into @.SCHOOLNUM,
@.STULINK,
@.SEQUENCE,
@.STATUS,
@.RELATION,
@.LASTNAME,
@.FIRSTNAME,
@.MIDDLENAME,
@.SALUTATION,
@.EMPLOYER,
@.OCCUPATION,
@.WRKTEL,
@.WRKEXTN,
@.ALTTEL,
@.TELEPHONE
if @.rec_count_before = 0
-- insert action
begin
print 'insert action'
print @.STULINK
print @.sequence
insert into dbo.EAI_ADM_PARENT
(STULINK,
SEQUENCE)
VALUES
(@.STULINK,
@.SEQUENCE)
end
else
-- update action
-- we can assume the record exists in EAI_A4000
begin
print 'update action start'
while @.counter <= @.rec_count_after
begin
update dbo.EAI_ADM_PARENT
set STATUS = @.STATUS,
RELATION = @.RELATION,
LASTNAME = @.LASTNAME,
FIRSTNAME = @.FIRSTNAME,
MIDDLENAME = @.MIDDLENAME,
SALUTATION = @.SALUTATION,
EMPLOYER = @.EMPLOYER,
OCCUPATION = @.OCCUPATION,
WRKTEL = @.WRKTEL,
WRKEXTN = @.WRKEXTN,
ALTTEL = @.ALTTEL,
TELEPHONE = @.TELEPHONE
from apple.APRN4000 P
where P.STULINK = @.STULINK
and P.SEQUENCE = @.SEQUENCE
-- get next record
select @.counter = @.counter + 1
if @.counter <= @.rec_count_after
begin
fetch inserted_curs
into @.SCHOOLNUM,
@.STULINK,
@.SEQUENCE,
@.STATUS,
@.RELATION,
@.LASTNAME,
@.FIRSTNAME,
@.MIDDLENAME,
@.SALUTATION,
@.EMPLOYER,
@.OCCUPATION,
@.WRKTEL,
@.WRKEXTN,
@.ALTTEL,
@.TELEPHONE
end
end
end
-- ending session
close inserted_curs
deallocate inserted_curs
print 'successful'
go
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:Oo3U0$D2EHA.3708@.TK2MSFTNGP14.phx.gbl...
> Possibly the trigger creates a cursor without deallocating it. Check the
> trigger code.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
> news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
>|||Where can I check the message meaning?
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:Oo3U0$D2EHA.3708@.TK2MSFTNGP14.phx.gbl...
> Possibly the trigger creates a cursor without deallocating it. Check the
> trigger code.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
> news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
>|||Can any one please help? Thanks.
""Allen Iverson"" <no_spam@.bk.com> wrote in message
news:Oa5t1LE2EHA.1408@.TK2MSFTNGP10.phx.gbl...
> In fact, this is the code, can anyone help:
>
> if exists (select id from sysobjects where name =
> 'apple.A4000_ins_upd_trg' and
> type = 'TR')
> begin
> drop trigger apple.A4000_ins_upd_trg
> print 'A4000_ins_upd_trg is dropped.'
> end
> go
> create trigger apple.A4000_ins_upd_trg on apple.APRN4000
> for update, insert
> as
> declare @.schoolyear varchar(1),
> @.UNID varchar(20),
> @.OBJECT_TYPE char(1),
> @.SCHOOLNUM varchar(3),
> @.STULINK numeric(5),
> @.SEQUENCE numeric(5),
> @.STATUS char(1),
> @.RELATION varchar(2),
> @.LASTNAME varchar(20),
> @.FIRSTNAME varchar(20),
> @.MIDDLENAME varchar(13),
> @.SALUTATION varchar(4),
> @.EMPLOYER varchar(40),
> @.OCCUPATION varchar(30),
> @.WRKTEL numeric(9),
> @.WRKEXTN varchar(4),
> @.ALTTEL numeric(9),
> @.TELEPHONE numeric(9),
> @.USERSTAMP varchar(10),
> @.PERMNUM varchar(12),
> @.GRADE varchar(2),
> @.FAMILYNUM numeric(5),
> @.ADDRESS1 varchar(50),
> @.ADDRESS2 varchar(40),
> @.AREA varchar(30),
> @.TERRITORY varchar(25),
> @.FAXNO varchar(11),
> @.ATTENTION varchar(30),
> @.REFCODE varchar(30),
> @.counter int,
> @.rec_count_before int,
> @.rec_count_after int
>
> -- initialization
> select @.schoolyear = '4'
> select @.counter = 1
>
> -- count how many records in inserted table
> select @.rec_count_after = count(STULINK)
> from inserted
> -- count how many records in before table
> select @.rec_count_before = count(STULINK)
> from deleted
>
> -- define cursor
> declare inserted_curs cursor for
> select SCHOOLNUM,
> STULINK,
> SEQUENCE,
> STATUS,
> RELATION,
> LASTNAME,
> FIRSTNAME,
> MIDDLENAME,
> SALUTATION,
> EMPLOYER,
> OCCUPATION,
> WRKTEL,
> WRKEXTN,
> ALTTEL,
> TELEPHONE
> from inserted
> open inserted_curs
> fetch inserted_curs
> into @.SCHOOLNUM,
> @.STULINK,
> @.SEQUENCE,
> @.STATUS,
> @.RELATION,
> @.LASTNAME,
> @.FIRSTNAME,
> @.MIDDLENAME,
> @.SALUTATION,
> @.EMPLOYER,
> @.OCCUPATION,
> @.WRKTEL,
> @.WRKEXTN,
> @.ALTTEL,
> @.TELEPHONE
> if @.rec_count_before = 0
> -- insert action
> begin
> print 'insert action'
> print @.STULINK
> print @.sequence
> insert into dbo.EAI_ADM_PARENT
> (STULINK,
> SEQUENCE)
> VALUES
> (@.STULINK,
> @.SEQUENCE)
> end
> else
> -- update action
> -- we can assume the record exists in EAI_A4000
> begin
> print 'update action start'
> while @.counter <= @.rec_count_after
> begin
> update dbo.EAI_ADM_PARENT
> set STATUS = @.STATUS,
> RELATION = @.RELATION,
> LASTNAME = @.LASTNAME,
> FIRSTNAME = @.FIRSTNAME,
> MIDDLENAME = @.MIDDLENAME,
> SALUTATION = @.SALUTATION,
> EMPLOYER = @.EMPLOYER,
> OCCUPATION = @.OCCUPATION,
> WRKTEL = @.WRKTEL,
> WRKEXTN = @.WRKEXTN,
> ALTTEL = @.ALTTEL,
> TELEPHONE = @.TELEPHONE
> from apple.APRN4000 P
> where P.STULINK = @.STULINK
> and P.SEQUENCE = @.SEQUENCE
> -- get next record
> select @.counter = @.counter + 1
> if @.counter <= @.rec_count_after
> begin
> fetch inserted_curs
> into @.SCHOOLNUM,
> @.STULINK,
> @.SEQUENCE,
> @.STATUS,
> @.RELATION,
> @.LASTNAME,
> @.FIRSTNAME,
> @.MIDDLENAME,
> @.SALUTATION,
> @.EMPLOYER,
> @.OCCUPATION,
> @.WRKTEL,
> @.WRKEXTN,
> @.ALTTEL,
> @.TELEPHONE
> end
> end
> end
>
> -- ending session
> close inserted_curs
> deallocate inserted_curs
> print 'successful'
> go
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote
> in message news:Oo3U0$D2EHA.3708@.TK2MSFTNGP14.phx.gbl...
>|||Actually, I doubt I found the cause of error.
Here is situation. I define trigger A in table TB1 and trigger B in table
TB2. The change in record in TB1 make trigger A act in which write record to
TB2 and make trigger B act in which write record to TB3. Much like a chain.
But then when I make change in TB1, I got error message saying cursor
already exists. Can anyone please help? Thanks.
""Allen Iverson"" <no_spam@.bk.com> wrote in message
news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
> When I want to make an update on a table which make a trigger action, it
> gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
> already exist"
> Can anyone please give me more info on msg 16915 or how to solve it?
> Thanks.
>|||Perhaps the inner trigger creates a cursor with the same name as already was
created by the outer
trigger?
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
""Allen Iverson"" <no_spam@.bk.com> wrote in message news:O1NItpQ2EHA.3324@.tk2msftngp13.phx.g
bl...
> Actually, I doubt I found the cause of error.
> Here is situation. I define trigger A in table TB1 and trigger B in table
> TB2. The change in record in TB1 make trigger A act in which write record
to
> TB2 and make trigger B act in which write record to TB3. Much like a chai
n.
> But then when I make change in TB1, I got error message saying cursor
> already exists. Can anyone please help? Thanks.
>
> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
> news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
>|||Can anyone please help?
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:usqoWuQ2EHA.1152@.TK2MSFTNGP14.phx.gbl...
> Perhaps the inner trigger creates a cursor with the same name as already
> was created by the outer
> trigger?
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
> news:O1NItpQ2EHA.3324@.tk2msftngp13.phx.gbl...
>|||You've got more problems with this trigger than just that error.
First of all, you have some serious logic bugs and some flawed usage.
1. Try to avoid cursors always, but especially inside of a trigger.
2. The INSERTED and DELETED tables will only store rows that were modified.
If Inserts, DELETED will be NULL; if Update, INSERTED and DELETED will
contain the same records; if Delete, INSERTED will be NULL. Neither of
these will have the same count as the base table unless this is the first
statement executed against the base table or was applied to the entire
table.
3. If you do use a cursor, you need to either code a GLOBAL CURSOR, and need
to check for its existence before you create it or use TEMPORARY cursors,
LOCAL.
4. The logic was a little conveluted; so, I'm not sure what the intent of
the trigger is but you could have simplified the code dramatically by using
constraints to handle most of this and then only using set-based statements
within the trigger for the specialized rules.
5. The error message you are getting is due to the trigger firing more than
once simultaneously due to concurrent users. The cursor already exists when
the second, or n th firing occurs.
Sincerely,
Anthony Thomas
""Allen Iverson"" <no_spam@.bk.com> wrote in message
news:%23fePwaD2EHA.2156@.TK2MSFTNGP10.phx.gbl...
When I want to make an update on a table which make a trigger action, it
gives me error "msg16915, level 16, State 1, Procedure ..." and "cursor
already exist"
Can anyone please give me more info on msg 16915 or how to solve it? Thanks.

Msg 9002, Level 17, State 4, Line 2

Hi fiaola
SQL Server has to log every data modification operation, every insert,
update and delete. If the log is full, nothing can be written to it and no
data modifications can be done. This has nothing to do with the tool you are
using.
Just do what the messages says. Look at the sys.databases view and tell us
what the log_reuse_wait_desc says. Also look at the recovery model
SELECT log_reuse_wait_desc, recovery_model_desc
FROM sys.databases
WHERE name = 'EventSentry'
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://blog.kalendelaney.com
"fiaola" <fiaola@.mail.com> wrote in message
news:uLj2q0WUIHA.4768@.TK2MSFTNGP02.phx.gbl...
> I'm trying to clear some data from a SQL DB table, but i'm getting this
> error:
> I'm just running a Delete Query using Date Diff function. I read in some
> web site that this maybe a problem with SQL Server Management Tools. I
> appreciate any help to get around this and any suggestions would be great.
> Msg 9002, Level 17, State 4, Line 2
> The transaction log for database 'EventSentry' is full. To find out why
> space in the log cannot be reused, see the log_reuse_wait_desc column in
> sys.databases
> Thanks for answering.
>
It might just be that your log is not big enough for the operation you were
doing.
How big is your log file, and is it set to autogrow?
You can get the information in the sys.files view in the database that is
having the problems.
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://blog.kalendelaney.com
"fiaola" <fiaola@.mail.com> wrote in message
news:uH1ss$YUIHA.5816@.TK2MSFTNGP06.phx.gbl...
> Thanks for the quick reply, here are the results.
> Log_Reuse_Wait_Desc = NOTHING
> Recovery_Model_Desc = SIMPLE
> "Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
> news:eMohs$WUIHA.4768@.TK2MSFTNGP02.phx.gbl...
>
sql

Wednesday, March 7, 2012

MSDTC unavailable / JoinTransaction returned 0x8004d01c

Hi! We have 2 database server. 1 at our company, while the other with a web
hosting company.
We wrote stored procedures to update data from tables in our company's
server to the web hosting company's server. Out of 13 of these stored
procedures, 5 failed, giving me the error message that looks like the one
below,
Server: Msg 8501, Level 16, State 1, Procedure sp_ExportCalendar, Line 9
MSDTC on server 'ORION' is unavailable.
Server: Msg 7391, Level 16, State 1, Procedure sp_ExportCalendar, Line 9
The operation could not be performed because the OLE DB provider 'SQLOLEDB'
was unable to begin a distributed transaction.
OLE DB error trace [OLE/DB Provider 'SQLOLEDB'
ITransactionJoin::JoinTransaction returned 0x8004d01c].
Can anyone help me explain what the error mean? I can post stored procedure
if required. Thanks.Hi this is one of the stored procedures that doesn't work. tsp is my user
name, server name.
CREATE PROCEDURE sp_ExportSysConf AS
BEGIN DISTRIBUTED TRANSACTION
IF EXISTS (SELECT * FROM [SysConf])
BEGIN
--Step1: Remove records that do not exist in CIM
DELETE FROM [tsp].[tsp].[tsp].[SysConf]
FROM [tsp].[tsp].[tsp].[SysConf] as C2
WHERE NOT EXISTS (SELECT [C1].[ConfName], [C1].[ConfValue],
[C2].[LastUpdate] FROM [SMSBASE].[DBO].[SysConf] as [C1] where
[C1].[ConfName] = [C2].[ConfName] and [C1].[ConfValue] = [C2].[ConfValue])
IF (@.@.error = 0)
BEGIN
-- no error --> Step 2: Insert new records from CIM
INSERT [tsp].[tsp].[tsp].[SysConf]([ConfName], [ConfValue])
SELECT [ConfName],[ConfValue]
FROM [SMSBASE].[DBO].[SysConf] as C2
WHERE NOT EXISTS (SELECT * FROM [tsp].[tsp].[tsp].[SysConf] as [C1]
where [C1].[ConfName] = [C2].[ConfName] and [C1].[ConfValue] =
[C2].[ConfValue])
IF (@.@.error = 0)
-- no error -> commit
COMMIT TRANSACTION
ELSE
-- error occurred -> rollback
ROLLBACK TRANSACTION
END
ELSE ROLLBACK TRANSACTION
END
ELSE ROLLBACK TRANSACTION
GO

MSDTC on server xx is unavailable

Hi:
We have 2 sql server(both sql2000) and using update/insert
triggers to replicate between the 2 servers. the
replication has been working and now We got this error
when doing an update:
ole/db provider returned message, new transaction cannot
enlist in the specified transaction coordinator. the
operation could not be performed because the oledb
provider 'sqloledb' was unable to begin a distributed
transaction.
So I restarted msdtc service on both sql servers, now when
running an update, I got msdtc on server
destinationservernm is unavailable, but both dtc services
are started. Any thoughts? thanks.Which OS version?
--
GertD@.SQLDev.Net
Please reply only to the newsgroups.
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.
Copyright © SQLDev.Net 1991-2003 All rights reserved.
"dean" <dean@.hotmail.com> wrote in message
news:016b01c377c6$693f1e40$a401280a@.phx.gbl...
> Hi:
> We have 2 sql server(both sql2000) and using update/insert
> triggers to replicate between the 2 servers. the
> replication has been working and now We got this error
> when doing an update:
> ole/db provider returned message, new transaction cannot
> enlist in the specified transaction coordinator. the
> operation could not be performed because the oledb
> provider 'sqloledb' was unable to begin a distributed
> transaction.
> So I restarted msdtc service on both sql servers, now when
> running an update, I got msdtc on server
> destinationservernm is unavailable, but both dtc services
> are started. Any thoughts? thanks.

MSDTC on server <Server-Name> is unavailable.

I got this error after I put an update trigger on a table which resides
in Database A and queries a table contained in Database B via a
linkserver. I have looked at the server and have bounced both the SQL
Server service and the DTC service and still it says that it can't find
it. Since this is a production server, resetting it is kind of out of
the question (but I'll do the old Microsoft fix if I have to). I was
just curious if anyone else has had this problem?Topper (Kinky.Taylor@.gmail.com) writes:
> I got this error after I put an update trigger on a table which resides
> in Database A and queries a table contained in Database B via a
> linkserver. I have looked at the server and have bounced both the SQL
> Server service and the DTC service and still it says that it can't find
> it. Since this is a production server, resetting it is kind of out of
> the question (but I'll do the old Microsoft fix if I have to). I was
> just curious if anyone else has had this problem?
Firewalls?
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Try the following from the command prompt:
msdtc -uninstall
then...
msdtc -install
This will reset the msdtc instance on the server.
Probably will require a reboot, but this has worked for me in the past.
Good Luck...John|||This is how I got into this predicament, but I'll try a reboot later
on.
Thanks

Saturday, February 25, 2012

msdtc is causing my cluster to be unavailiable via it's virtual na

I have windows 2003 sp1 running in a 2-node cluster. The cluster is running
sql sp4. I tried failing over my cluster after a windows update and i'm not
sure if that's what threw my server's off or something else. But here's the
situation. I currently have the cluster group running on node 2, the msdtc
running on node 1 and the sql group running on node 2. When i move the msdtc
group to node 2 (ie.. the server which should be running all services)i cant
ping the sql virtual server by name or ip. I am however able to contact the
individual servers via their names sql1 and sql2. So basically i lose my
connection to the virtual sql server throughout my network when the msdtc is
running on the same server. Is there an update? upgrade? to the msdtc or
anything else i can do to fix this issue?
Ohh yes and there's no errors in the event log.
What are the Resource Group names, Resource Network Names, and Resource IP
addresses? What other resources a apart of each group?
Sounds like a DNS registration issue. Does the SQL Server group go offline
or fail over when the MSDTC group is moved to node 2?
Sincerely,
Anthony Thomas

"Sunny" <Sunny@.discussions.microsoft.com> wrote in message
news:12879549-04B5-454B-A44C-C075061EAEC1@.microsoft.com...
> I have windows 2003 sp1 running in a 2-node cluster. The cluster is
running
> sql sp4. I tried failing over my cluster after a windows update and i'm
not
> sure if that's what threw my server's off or something else. But here's
the
> situation. I currently have the cluster group running on node 2, the
msdtc
> running on node 1 and the sql group running on node 2. When i move the
msdtc
> group to node 2 (ie.. the server which should be running all services)i
cant
> ping the sql virtual server by name or ip. I am however able to contact
the
> individual servers via their names sql1 and sql2. So basically i lose my
> connection to the virtual sql server throughout my network when the msdtc
is
> running on the same server. Is there an update? upgrade? to the msdtc or
> anything else i can do to fix this issue?
> Ohh yes and there's no errors in the event log.

MSDTC error

Hi,
I have econnection code in front end app to do the update. I got the
following error,
The transaction manager has disabled its support for remote/network
transaction...
I checked app server the MSDTC has enabled
Any ideas why?
ThanksRead the replies...think youre answer in there.
Just google my friend ;)
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=230390&SiteID=1
First verify the "Distribute Transaction Coordinator" Service is
running on both database server computer and client computers
1. Go to "Administrative Tools > Services"
2. Turn on the "Distribute Transaction Coordinator" Service if it is
not running
If it is running and client application is not on the same computer as
the database server, on the computer running database server
1. Go to "Administrative Tools > Component Services"
2. On the left navigation tree, go to "Component Services > Computers
> My Computer" (you may need to double click and wait as some nodes
need time to expand)
3. Right click on "My Computer", select "Properties"
4. Select "MSDTC" tab
5. Click "Security Configuration"
6. Make sure you check "Network DTC Access", "Allow Remote Client",
"Allow Inbound/Outbound", "Enable TIP" (Some option may not be
necessary, have a try to get your configuration)
7. The service will restart
8. BUT YOU MAY NEED TO REBOOT YOUR SERVER IF IT STILL DOESN'T WORK
(This is the thing drove me crazy before)
On your client computer use the same above procedure to open the
"Security Configuration" setting, make sure you check "Network DTC
Access", "Allow Inbound/Outbound" option, restart service and computer
if necessary.
On you SQL server service manager, click "Service" dropdown, select
"Distribute Transaction Coordinator", it should be also running on
your server computer.
Hope it helps,|||the server is virtual server running window 2000 terminal
"mecn" <mecn2002@.yahoo.com> wrote in message
news:%23myijFJ8HHA.1484@.TK2MSFTNGP06.phx.gbl...
> Hi,
> I have econnection code in front end app to do the update. I got the
> following error,
> The transaction manager has disabled its support for remote/network
> transaction...
> I checked app server the MSDTC has enabled
> Any ideas why?
> Thanks
>

Monday, February 20, 2012

MSDTC

Hi,

I am running SQl 7.0 (SP4) on Windows XP Professional (SP2). Whenever I try an insert/update type of activity, the System returns the following message :

Server: Msg 8501, Level 16, State 3, Line 2
MSDTC on server 'SERVER' is unavailable.

However, all the required services including MSDTC are running on the System.

Please help ASAP.

Thanks & Regards - Rajesh Pathak

It sounds like DTC is turned off on the other machine. Can you confirm that it is on and try again?

Thanks,
Sam Lester (MSFT)

|||Hello Sam,

Thanks for the prompt reply. As a matter of fact, trying any operation on the Server System which itself runs SQL 7.0 returns the MSDTC not running message. If it works on the Server System then I can try debugging problems on other Client Systems.

Kindly let me have probable resolution to this.

Thanks & Regards - Rajesh Pathak