.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

SqlCommand.Cancel() method doesn't do what its supposed to do

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :Sql Server
Hi guys!

I have some issues with cancelling the execution of a long-during sql-query.
Please take a look at the winforms-code below.

When I open up the SQL-Profiler, the execution of the query isn't cancelled by calling Cancel() on the command-object.
Does anyone have an idea, why not? Is it a feature which I have to enable on the sql-server?

Regards, Florian
  public partial class Form1 : Form
    string _commandText;
    SqlConnection _connection;
    IAsyncResult _result;
    SqlCommand _command;

    public Form1()

    private void Form1_Load(object sender, EventArgs e)
      _commandText = "select * from HugeTable";

    private void InitializeOpenedConnection()
      if (_connection == null || _connection.State == ConnectionState.Closed)
        _connection = new SqlConnection(GetConnectionString());
      if (_connection.State != ConnectionState.Open)

    private void btnStart_Click(object sender, EventArgs e)
      _command = new SqlCommand(_commandText, _connection);

      _result = _command.BeginExecuteReader();
      _command.StatementCompleted += new StatementCompletedEventHandler(_command_StatementCompleted);

View Complete Post

More Related Resource Links

Sys.Data.DataContext.saveChanges method doesn't send update to server after DataServiceException ex

Hello,I have a page with a simple form that updates a single record in a table in my database.The database is accessed via WCF Data Services. To load and save data from/to the server, I usethe Sys.Data.DataContext object provided by the ASP.NET AJAX library. When the "save" button on theform is clicked, I use the saveChanges method of the Sys.Data.DataContext object to send all changes to the server.Also, at the server side, I use an interceptor that checks the "Price" fields of the record, and throws a DataServiceException exception when the contents of the field is a negative number.Both the JavaScript and the interceptor (in C#) are copied below.Here is the interesting thing:When I enter a negative price in the form, the interceptor throws the exception and my form shows an error message. Good.However, if I then make one of the other fields in the form a bit shorter (for example from "abcd" to "abc"),the saveChanges method doesn't send the data to the server. But it does call the success callback that I passed in to saveChanges, creating the impressionthat the data has been saved. This happens while the Price field is still negative. I used Fiddler to make sure thatno message is sent to the server. Also, the interceptor doesn't get executed.The weird thing is that if I make one of the fields a bit longer instead (for example &q

WCF WebGet method doesn't work from browser

I'm trying to operate a WCF Method from the browser, i opened a basic WCF Project and added the Webget attribute, my interface is this: [ServiceContract] public interface IService1 { [WebGet(UriTemplate = "GetData?value={value}", BodyStyle = WebMessageBodyStyle.Bare)] [OperationContract] string GetData(int value); [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); // TODO: Add your service operations here } and i'm inserting the following URL in the Browser: http://localhost:3122/Service1.svc/GetData?value=3 i get "The webpage cannot be found" there must be missing something in my configuration , what do i have to add ? this is my configuration : <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing

IsAjaxRequest method doesn't work with some IE requests

Hey, I've just discovered that the X-Requested-With header in IE is always "XMLHttpRequest, XMLHttpRequest" instead of just "XMLHttpRequest". I found the reason in MicrosoftMvcAjax.debug.js at line 280 (MVC 2.0). Seems there is no need to add this header again as it is already done in Microsoft AJAX Library. And because of this IsAjaxRequest extension method doesn't work anymore if there is no X-Requested-With param in the request body. And this make X-Requested-With header useless in IE. In Firefox there is no problem as it doesn't append but replace the existing header value. Not tested in other browsers. Can someone from the MVC team comment on this? Thanks in advance.

Abort() method of wcf client proxy doesn't release session after catching FaultException



I have created a simple wcf service hosted in IIS and wcf client and figured out that when u catch a FaultException from the wcf service and then call client.Abort() to release the session (as the microsoft samples said) it doesn't release the session and hangs up on the 11th call.

Here is example:

Wcf Service:

public interface IService1 
    string GetData(int value); 
public class Service1 : <

Abort() method of wcf client proxy doesn't release session after catching FaultException



I have created a simple wcf service hosted in IIS and wcf client and figured out that when u catch a FaultException from the wcf service and then call client.Abort() to release the session (as the microsoft samples said) it doesn't release the session and hangs up on the 11th call.

Here is example:

Wcf Service:

public interface IService1 
    string GetData(int value); 
public class Service1 : <

Pick Activity doesn't cancel other branches when first Branch Trigger completes


I have a Pick Activity with 2 branches:

Branch 1 contains a Trigger an Delay activity with TimeSpan of 1 minute and a WriteLine before and after so I can check the executing times.

Branch 2 contains a Trigger with an InvokeMethod activity which performs some action, that when it takes longer than 1 minute should be cancelled. Also this Trigger has 2 Writelines to check the executing times. The InvokeMethod has the flag RunAsynchronously set to true.

Both branches Action activities contain another WriteLine.

When I run the Workflow, I see the following:

12:24:47 Branch 1 started
12:24:47 Branch 2 started
12:25:47 Branch 1 ended
12:26:46 Exception on my client The request channel timed out while waiting (sendTimeout="

Microsoft JScript runtime error: Object doesn't support this property or method



When I am updating dropdown of parent window from popup it shows error JScript runtime error. But I can able to clear the dropdown. When I am adding only the problem is occuring. I have pasted the code below

var ddlVendor = window.opener.aspnetForm.document.getElementById('ctl00_DefaultContent_ddlVendor');

//Clears the state combo box contents.

for (var count = ddlVendor.options.length-1; count >-1; count--)


ddlVendor.options[count] =


var stateNodes = listNode.getElementsByTagName('Table1/UserName');

var stateIds = listNode.getElementsByTagName('Table1/Password');

web service method doesn't work


DEar all,


I have developed a asp.net website in visual studio 2008, I have Sharepoint server 2010 installed n configured.

In my asp.net website I have a function which will create a folder in the sharepoint site.

My problem is when I have published the website, the folder is not being created.

But when i am debugging it, the folder is being created in the sharepoint site.

My Code is as follows:



String CreateFolder(string sfolderName)



Accordion: object doesn't support this property or method


I have simple accordion:

$("#accordion").accordion({ autoHeight: false, active: false });


This causes the Microsoft JScript runtime error: Object doesn't support his property or method.


All other JQuery code works fine. Anyone has any idea why this is causing this error??
thanks in advance.

Sqlcommand in default dabase using method

Hi All,

I Used Three Data In DataBase like product,price,discount........i give default value off discount ...0.......I miss Default

field to enter input.. When I Run The Program . It Shows Error like(Incorrect Syntax Near ')'....Please Help Me For This

sql is
create table products(product nvarchar(max),
price numeric(18,2),
discount numeric(18,2) default 0)

used command is

Com=New sqlcommand("insert into pro values('" & textbox1.text &"'," & textbox2.text &"," & textbox3.text &")",con)


Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.

ASP.Net Gridview Edit Update Cancel Commands

In ASP.Net 2.0, GridView Control also provides the functionality to edit and update the data retrieved from the database using CommandField template. You can cancel the action using Cancel Command of the CommandField. GridView consists of events that can be used to perform the actions like edit, update and cancel upon the Data items displayed in the ASP.Net GridView Data Control.

SqlCommand.ExecuteNonQuery() returns -1 when doing Insert / Update / Delete

Sometimes you end up with a return value of -1 when using the SqlClient.SqlCommand.ExecuteNonQuery method.

Why is that?

Well, the ExecuteNonQuery method is there for statements for changing data, ie. DELETE / UPDATE /INSERT, and the returned value are the number of rows affected by that statement.

When checking the documentation we can see that there are some conditions that return -1.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.

When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of

rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

Sys.Net.WebServiceFailedException: The server method '' failed with the following error:



Let's say we have 2 time consuming functions, aaa and aaa1 inside a aspx page.

        public static string aaa(int i)
            return i.ToString();

        public static string aaa1(int i)
            return i.ToString();



        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        <span id="displayspan"></span>
        <br />
        <input type="button" value=

Beginner: this doesn't make sense to me


Do you need and "empty" script tag in the head to run scripts that are in the body?  Also, can you run JQuery scripts if they're in the <head> tag?  The first sample only works if the JQuery script is in the form (and body) tag, not in the head - even if I add $(document).ready(function() { });

This works

<head runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" />
<script type="text/javascript">
<form id="form1" runat="server">
<a href="">Here is a link</a>
<script type="text/javascript">
$('a').click(function () {
alert("you clicked me!");


This doesn't work.  Notice I removed the second <script> tag from the head

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="serve

Jscript error: Object does not support property or method


 Hi, i have little knowledge on javascript but i need to use this code get from somewhere for a jquery to work.

I face this "Jscript runtime error: Object does not support property or method" whenever im trying to run this page.

In my experience, im get this error msg 9 out of 10 times i use javascript in my system.

Im using Microsoft Visual web developer 2008, i wonder if this is related to my problem, i not sure there is anything i need to add as reference or update anything.

But anyway, in short, i just couldn't use javascript code when using this development tool because of this sort of error.

Anyway, it happen that last time i tried use the same type of jquery code in another project and it seems to work well without an error.

But now when im try to use it again in this recent project i created, it come out with this error and i have no idea how to solve it even look through google and this forum.

It doesn't really seems like its the code problem itself although im not sure, because any javascript code just couldn't work.

So below is my code that i need to use.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
<script type="text/javascript" src=&quo

replacing ok and cancel button of an alert message with YES an NO button in asp.net web application.


i want to replace ok and cancel button of an alert message with YES an NO button in asp.net web application.When a user will click yes the data will be saved in the database and if user clicks that will act as a reset button and do not save the data in database and the control will move with as usual to the redirect page.Any pointers will be highly appreciated.I am usin g C# language.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend