Re: ExecuteNonQuery stops program

From: W.G. Ryan eMVP (WilliamRyan_at_NoSpam.gmail.com)
Date: 01/16/05


Date: Sun, 16 Jan 2005 17:47:09 -0500

I'd Debug.Writeline the command that's being fired and see if it will work
in Query Analyzer - or run a trace and see what's happening w/ it. I've
never quite seen that behaviour you mention - but using Profiler will help
you see what's going on back there.

Just as an aside - you may want to paramaterize your query for performance,
security etc. Also, if this is being called 10,000 times or whatever, just
check that sqlConnection3.State==ConnectionState.Closed - that way you
aren't creating a string each time just to compare it to one. In a loop
this big that could affect performance a little . I'd also just trap a
SqlException here b/c the line your trying - that should be the only type of
exception that would be raised. Just on GP I'd bump the Close into a
finally block.

Good Luck

Bill

-- 
W.G. Ryan MVP (Windows Embedded)
TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"rafal" <rx409@gazeta.pl> wrote in message
news:csecfr$50q$1@inews.gazeta.pl...
> I run this code below which is part of method.
> ds.Tables["tabelka"].Rows.Count has always value 13117 but sometimes the
> code executes only 1000 or 12000 times etc and freezes without error or
> exception not coming to the end of the method. In debug window it prints
> "before" which means it stops during or before executing
> upd.ExecuteNonQuery();
> I don' know what is going on. Thanks for help.
>
>
> for (int y = 0; y < ds.Tables["tabelka"].Rows.Count; y++)
> {
> string account_id = ds.Tables["tabelka"].Rows[y][0].ToString();
> string date = ds.Tables["tabelka"].Rows[y][1].ToString();
> int temp1 = 0;
> double temp2 = 0.00;
> int val = 0;
> val = y/1874;
> string updateCommand = "update wielka set "+columnName+"="+val.ToString()+
"
> where account_id="+account_id+" and date="+date;
> SqlConnection sqlConnection3 = new SqlConnection(connString);
> SqlCommand upd = new SqlCommand(updateCommand, sqlConnection3);
> if (sqlConnection3.State.ToString() == "Closed")
> {
> sqlConnection3.Open();
> }
> try
> {
> Console.WriteLine("before");
> upd.ExecuteNonQuery();
> Console.WriteLine("discretization "+y);
> }
> catch (Exception exc)
> {
> Console.WriteLine("Exception 3: "+exc.ToString());
> Console.WriteLine("UpdateCommand: "+updateCommand);
> }
> sqlConnection3.Close();
> }
>
>


Relevant Pages

  • Re: Exception: The SqlTransaction has completed; it is no longer usabl
    ... > I hv encountered this exception 'The SqlTransaction has completed; ... returning around 9000 rows in a DataSet and back to the app. ... > When that exception is thrown, I tried running the same stored procedure ... > I was thinking if Query Analyzer can return data very quickly... ...
    (microsoft.public.dotnet.framework.adonet)
  • RE: TrackedMessages_Copy_BizTalkMsgBoxDb error.
    ... I did compare the code between environments and its exactly the same. ... run it through query analyzer and know its line 79 where it is failiing. ... on our production server is throwing an exception as follows.. ...
    (microsoft.public.biztalk.general)
  • RE: error establishing socket error
    ... For some common causes of this exception and troubleshooting, ... I would also recommend testing with Query Analyzer from the machine that ... whether this problem is specific to the JDBC driver or if you just cannot ... | public SqlTest() throws Exception ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: SqlDataAdapter.Fill throws me an IndexOutOfRangeException
    ... You showed us what you have on a server side, but actually did not show the ... code, which throws the exception. ... Val Mazur ... > when I run the query from query analyzer I get a valid, ...
    (microsoft.public.dotnet.framework.adonet)