user2778395
user2778395

Reputation: 549

asynchronous call to stored procedure in MVC Controller example

I have never used asynchronous calls, could some one please provide me a sample how to call a SQL stored procedure from MVC controller ?

public ActionResult ReProcess(string uname)
{

SqlCommand cmd=new SqlCommand();

cmd.Connection = cnn;

cnn.Open();

cmd.CommandText = "dbo.userdetails_sp";

cmd.CommandType = CommandType.StoredProcedure;

cmd.CommandTimeout = 0;

cmd.Parameters.Add("@userId", System.Data.SqlDbType.VarChar).Value = uname; ;

cmd.ExecuteNonQuery();



}

Upvotes: 0

Views: 1249

Answers (1)

MichaelS
MichaelS

Reputation: 3831

You can use the Task class to encapsulate a method and then run it asyncronously: http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.aspx

var t = Task.Factory.StartNew(() => DoAction());

Upvotes: 1

Related Questions