Re: confusing transactions with sqldmo
From: David Gugick (davidg-nospam_at_imceda.com)
Date: 12/25/04
- Next message: RJ: "cardinality"
- Previous message: Paul fpvt2: "Re: How to clear memory usage after executing queries ?"
- In reply to: Neil: "Re: confusing transactions with sqldmo"
- Next in thread: Neil W: "Re: confusing transactions with sqldmo"
- Reply: Neil W: "Re: confusing transactions with sqldmo"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 25 Dec 2004 02:05:17 -0500
Neil wrote:
> Sorry, I had sqldmo on my mind. I meant ado.net (using C#). Here is
> the source code with everything but the essentials stripped out. The
> program creates a bunch of threads and then performs the code below
> in each thread.
>
> Like I said, when running from many different Query Analyzer windows,
> these appear to run simultaneously. However, when started in many
> threads from the same program, they seem to run single threaded.
>
> To refresh your memory, sp_test_proc contains the following inside a
> tight loop:
>
> begin trans
> update employees with (rowlock) set address = reverse(address) where
> employeeid = @random
> commit work
>
> I hope this is clear. Thanks for your input..
>
> --- code --
>
> // Connecting:
> string
> s=server=(local);Trusted_Connection=yes;database=master;connectiontimeout=10
> ;Net=dbmslpcn;
> return new SqlConnection(s);
>
> // Create SqlCommand:
> // conn is created connection
> conn.Open(); //open connection
> SqlCommand command = conn.CreateCommand(); //create command
>
> // Set up properties of SqlCommand:
> // this is the procedure that does the update loop I mentioned before
> command.CommandText = "sp_test_proc";
> command.CommandType = CommandType.StoredProcedure;
> command.CommandTimeout = 0; //never time out
>
> // Set up parameters to call stored procedure:
>
> SqlParameter returnval =
> command.Parameters.Add("RETURN_VALUE",SqlDbType.Int);
> returnval.Direction = ParameterDirection.ReturnValue;
>
> SqlParameter parm1 =
> command.Parameters.Add("@parm1",SqlDbType.NVarChar,50); parm1.Value =
> ... ;
>
> SqlParameter parm2 = ...
>
> // Call stored procedure:
> command.ExecuteNonQuery();
> object value = command.Parameters["RETURN_VALUE"].Value;
> // value is return value of stored procedure
>
> Close connection:
> conn.Close();
>
I don't think just because you are running multiple threads you can run
multiple SQL statements. AFAIK, one SQL statement per connection unless
you are using something like the Prepare/Execute model of execution.
Otherwise, one SQL statement per connection. In any case, you need to
make an asynchronous call. I don't see that you specified the call is
asynchronous anywhere in your code.
So, you'll need multiple connections and need to use asynchronous calls,
just like Query Analyzer does.
-- David Gugick Imceda Software www.imceda.com
- Next message: RJ: "cardinality"
- Previous message: Paul fpvt2: "Re: How to clear memory usage after executing queries ?"
- In reply to: Neil: "Re: confusing transactions with sqldmo"
- Next in thread: Neil W: "Re: confusing transactions with sqldmo"
- Reply: Neil W: "Re: confusing transactions with sqldmo"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|