Re: ?At a loss? ExecuteNonQuery executing my Insert Statement 3 times in debug mode
From: Mike (mraeNOSPAM_at_NOSPAMATALLcalibrus.com)
Date: 02/11/04
- Next message: Marshal Antony: "Re: lazy load, very lazy ...."
- Previous message: Yair Cohen: "Re: lazy load, very lazy ...."
- In reply to: William Ryan eMVP: "Re: ?At a loss? ExecuteNonQuery executing my Insert Statement 3 times in debug mode"
- Next in thread: Scott M.: "Re: ?At a loss? ExecuteNonQuery executing my Insert Statement 3 times in debug mode"
- Reply: Scott M.: "Re: ?At a loss? ExecuteNonQuery executing my Insert Statement 3 times in debug mode"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 11 Feb 2004 16:19:46 -0700
I can very clearly see 3 records in the database. And the table does have a
primary key and and it set as an Identity field. Each record is given a
unique ID.
Ive been just stepping over the methods where I am doing the inserts and it
hasn't happen since. The debugger must be executing the code several times
to get the value the ExecuteNonQuery is returning to display in the various
debug windows I have open. Seems like a giant bug that is incredibly
annoying.
Everything has been working great since I stopped stepping through the
method.
"William Ryan eMVP" <dotnetguru@comcast.nospam.net> wrote in message
news:OHhL2HC8DHA.2736@TK2MSFTNGP10.phx.gbl...
> If 1 is being returned as the records affected, I'd be the house that the
> insert isn't executing 3 times...I think the watch list issue has already
> been brought up, but if all else fails, put a PK on the table temporarily
> and see when you get a violation. you may also want to change where you
> call this from and see if it happens repeatedly even if you call it from
> another proc.
> "Mike" <mraeNOSPAM@NOSPAMATALLcalibrus.com> wrote in message
> news:eztx1AA8DHA.2764@TK2MSFTNGP09.phx.gbl...
> > Well the way I can tell that the Insert statement is being executed 3
> times
> > is because there are 3 records in the database.
> >
> > 1 is being returned by the ExecuteNonQuery command. No there aren't any
> > triggers running.
> >
> >
> > Mike
> >
> > "William Ryan eMVP" <dotnetguru@comcast.nospam.net> wrote in message
> > news:eqtJF8$7DHA.2432@TK2MSFTNGP10.phx.gbl...
> > > Mike:
> > >
> > > How do you know it's being executed 3 times? If this isn't in a loop
> and
> > > there's not multiple threads running it, I would be the house that
it's
> > not
> > > really executing three times.
> > >
> > > As an aside, I'd really lose the dynamic sql and either use Parameters
> or
> > > ideally make it a proc...
> > >
> > > sql = "INSERT INTO tblStipen(EmployeeId, StipenTypeID, Units, Amount,
> > > AddHours, PayrollID) Values
> > > @EmployeeId, @StipType, @Units, @Amount, @Hours, @PayrollID)";
> > >
> > > cmd.Parameters.Clear();
> > > cmd.Parameters.Add("@EmployeeId", SqlDbType.Employee'sType ie Int,
> > > Length).Value = _employeeid;
> > > cmd.Parameters.Add("@StipType", SqlDbType.SmallInt).Value = 3;
> > >
> > > etc.
> > >
> > > I'm guessing when you say it's gettting executed 3 times it's based on
> the
> > > return value being 3? First verify that it's not actually being
> inserted
> > 3
> > > times by querying the DB. Since it's a simple insert, I can't see how
3
> > > records could be getting inserted, but you may have a trigger or
> something
> > > that's causing this number to behave funny.
> > >
> > > First let me know if it's the number 3 as a return value that's the
> issue
> > or
> > > if there are verifiably 3 records getting inserted.
> > >
> > > HTH,
> > >
> > > Bill
> > > "Mike" <mraeNOSPAM@NOSPAMATALLcalibrus.com> wrote in message
> > > news:uH1Jts$7DHA.2540@TK2MSFTNGP11.phx.gbl...
> > > > I know this sounds strange but I am at a loss. I am calling a
simple
> > > > funtion that opens a connection to a SQL Server 2000 database and
> > executes
> > > > an Insert Statement.
> > > >
> > > > private void AddMinimunWageStipen(string payrollid,double amount)
> > > > {
> > > >
> > > > System.Data.SqlClient.SqlConnection cn = null;
> > > > System.Data.SqlClient.SqlCommand cm = null;
> > > >
> > > > string sql = "INSERT INTO tblStipen (EmployeeID, StipenTypeID,
Units,
> > > > Amount, AddHours, PayrollID) ";
> > > > sql+= "VALUES (" + _employeeid + ", 3, 1, " + amount + ", 0, " +
> > > payrollid
> > > > + ")";
> > > >
> > > > try
> > > > {
> > > > cn = new
> > > > System.Data.SqlClient.SqlConnection(PayrollSystem.Data.SQLSERVER);
> > > > cn.Open();
> > > > cm = new System.Data.SqlClient.SqlCommand(sql,cn);
> > > > int flag = cm.ExecuteNonQuery();
> > > > cn.Close();
> > > > }
> > > > catch(Exception ex)
> > > > {
> > > > throw ex;
> > > > }
> > > > finally
> > > > {
> > > > cm.Dispose();
> > > > cn.Dispose();
> > > > }
> > > >
> > > > }
> > > >
> > > > When I run this code in the debugger and step through this funtion,
> when
> > I
> > > > execute the line "int flag = cm.ExecuteNonQuery();" the Insert
> > Statement
> > > > gets exectued 3 times. So I have the same record in the database 3
> > times??
> > > > And I know the the code is only being exectuted once. The function
> > isn't
> > > > being called 3 times with the same parameters being passed in. I
am
> > also
> > > > not doing any special threading.
> > > >
> > > > If I run the program without stopping in this function the code
behave
> > > like
> > > > it should and the record only gets inserted once.
> > > >
> > > > Is there something I am missing? Has anyone else ran into this
> problem?
> > > >
> > > > Thanks in advance,
> > > >
> > > > Mike R
> > > >
> > > >
> > >
> > >
> >
> >
>
>
- Next message: Marshal Antony: "Re: lazy load, very lazy ...."
- Previous message: Yair Cohen: "Re: lazy load, very lazy ...."
- In reply to: William Ryan eMVP: "Re: ?At a loss? ExecuteNonQuery executing my Insert Statement 3 times in debug mode"
- Next in thread: Scott M.: "Re: ?At a loss? ExecuteNonQuery executing my Insert Statement 3 times in debug mode"
- Reply: Scott M.: "Re: ?At a loss? ExecuteNonQuery executing my Insert Statement 3 times in debug mode"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|