Solved

"Multiple step OLE DB operation generate error" on MSSQL2K and ADO/Command.Execute

Posted on 2004-08-07
2
277 Views
Last Modified: 2008-02-01
I'm getting error "Multiple step OLE DB operation generate error..."
when inserting a new record into the following table:

CREATE TABLE Profession
(
  SeekerID INTEGER NOT NULL,
  SkillName NVARCHAR(30) NOT NULL,
  JobType SMALLINT,
  SubType SMALLINT,
  Prime BIT NOT NULL DEFAULT 1,
 
  PRIMARY KEY (SeekerID, SkillName),
  FOREIGN KEY (SeekerID) REFERENCES Seekers (SeekerID),
  FOREIGN KEY (JobType) REFERENCES JobTypes (TypeID),
  FOREIGN KEY (SubType) REFERENCES SubTypes (SubID),
  CHECK (JobType IS NOT NULL OR SubType IS NULL)
)

The JScript code is simple:

cmd.CommandText = "INSERT INTO Profession (SeekerID, SkillName, JobType, SubType, Prime) VALUES (?, ?, ?, ?, ?)";
cmd.CommandType = adCmdText;
cmd.Prepared = true;
cmd.Parameters.Append(cmd.CreateParameter('SeekerID', adInteger, adParamInput));
cmd.Parameters.Append(cmd.CreateParameter('SkillName', adVarWChar, adParamInput, 30));
cmd.Parameters.Append(cmd.CreateParameter('JobType', adSmallInt, adParamInput));
cmd.Parameters.Append(cmd.CreateParameter('SubType', adSmallInt, adParamInput));
cmd.Parameters.Append(cmd.CreateParameter('Prime', adBoolean, adParamInput));
cmd('SeekerID') = seeker_id;
cmd('SkillName') = pro_skillname;
cmd('JobType').Value = null;
cmd('SubType').Value = null;
cmd('Prime').Value = true;
cmd.Execute();

I'm executing a long transaction like:

con.BeginTrans()
//insert into master table
....
//delete from sub table # 1
....
//insert into sub table # 1
....

//delete from sub table # 5
....
//insert into sub table # 5
....
con.CommitTrans();

The table Profession is 3th table. I use one Command (cmd) object for all INSERT operations.
Hope Command object automatically clears its Parameters collection when CommandText
property is updated.
The DELETE operations do not use Command object because they are simple, so I use
direct con.Execute() for them.

My platform: WinXP Pro, MSSQL 2000, MDAC 2.8 and JScript 5.6

0
Comment
Question by:tumur
2 Comments
 
LVL 9

Accepted Solution

by:
crescendo earned 500 total points
ID: 11742757
I think you need to make the command object a new object each time.

Also, do you need a ".value" after cmd('SeekerID') and cmd('SkillName') or is it the default property?
0
 

Author Comment

by:tumur
ID: 11742877
Yes, Thank you! The Command's Parameters is not cleared
when a new command is assigned to CommandText.
And it does not have any method that clears above
collection. Only way is to create new Command or
delete each Parameter in the collection.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MS SQL export CSV & schedule It 9 44
SQL 2012 and SQL 2014 in memory database 11 31
INSERT INTO SELECT JOIN THING 2 25
c# code 19 59
In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now