C# - ObjectContext.ExecuteStoreCommand - Clear Parameters Between Calls?
Feb 11, 2011
I am making multiple calls to ObjectContext.ExecuteStoreCommand with different commands and different parameters, although I use the same parameter list (object) for a several of the commands. I am getting the following exception:
System.ArgumentException: The SqlParameter is already contained by another SqlParameterCollection.
Is there a way to clear parameters between calls as I would do with straight up ADO.NET?
Updated with a code sample:
string sqlDeleteWebUserGreen = "delete WebUserGreen where WebUserId = @WebUserId";
string sqlDeleteWebUserBlue = "delete WebUserBlue where WebUserId = @WebUserId";
var argsDeleteWebUserXref = new DbParameter[] {
new SqlParameter { ParameterName = "WebUserId", Value = user.WebUserId }
rowsAffectedDeleteWebUserXref += base.context.ExecuteStoreCommand(sqlDeleteWebUserGreen, argsDeleteWebUserXref);
rowsAffectedDeleteWebUserXref += base.context.ExecuteStoreCommand(sqlDeleteWebUserBlue, argsDeleteWebUserXref);
UPDATE
Basically I am unable to find any better way of doing this, so I ended up accepting the answer below. The only difference is that I simply put the creation of the parameter into a separate method, so my calls look like base.context.ExecuteStoreCommand(sqlDeleteWebUserBlue, MethodThatWillGiveMeTheParameterArray());
View 1 Replies
Similar Messages:
Mar 31, 2010
I have a complex page which has a series of panels and buttons.
one of those buttons pulls up an a wizard control.
the user does not need to go to the finsih button of the wizard if they wish to cancel the wizard.
What I want to do is to clear the values of a wizard as it is being called by a button click.
Uncle google tells me a solution is to use a URL redirect to effectively reload the page into memory. This would also destroy the view state of my page for the nonwizard controls which I dont want to do.
I cant put the wizard into an Iframe (company policy) so I cant just reload the iframe.
I dont want to go step by step and control by control to clear the values - Also the wizard is not using databinding.
View 3 Replies
May 27, 2010
I have a gridview control with delete asp:ImageButton for each row of the grid. What I would like is for a jquery dialog to pop up when a user clicks the delete button to ask if they are sure they want to delete it.
So far I have the dialog coming up just fine, Ive got buttons on that dialog and I can make the buttons call server side methods but its getting the dialog to know the ID of the row that the user has selected and then passing that to the server side code. The button in the page row is currently just an 'a' tag with the id 'dialog_link'. The jquery on the page looks like this:
$("button").button();
$("#DeleteButton").click(function () {
$.ajax({
[code]...
The dialog itself is just a set of 'div' tags. Ive thought of lots of different ways of doing this (parameter passing, session variable etc...) but cant figure out how to get any of them working.Any ideas are most welcome
View 1 Replies
Jul 25, 2010
I need from a ascx (control_A) load dynamically another user control (Control_B), for do that I use LoadControl passing parameters to the control_B's constructor, in this way:
View 7 Replies
Feb 17, 2010
I have the following Page_Load function...
protected void Page_Load(object sender, EventArgs e)
{
XmlDataSource1.Data = GetXmlFromFile(Request.QueryString["file"]);
XmlDataSource1.DataBind();
Repeater1.DataBind();
}
The page in which this Page_Load resides is called by a parent page. Each time this Page_Load gets called the value of "file" in the query string will be different. So each time I will be receiving the XML contents from a different file which are inserted into the XmlDataSource and then bound against by the Repeater. Getting the XML data from the file works great but when I bind against the repeater that only works the first time through Page_Load. Each time after that when this code is executed the same results from the first XML file are displayed in the repeater.
What am I missing here. How can I get the XML data to be bound against the repeater on each page load instead of just the first one?
View 3 Replies
May 10, 2010
I have a webservice (ASP.NET) deployed on a webfarm. A client application consumes it on daily basis. The problem is that some of its calls are duplicated (with difference of milliseconds). For example I have a function Foo(string a,string b). The client app calls this webmethod as Foo('test1','test2') once but my log shows that it is being called twice or sometimes 3 or 4 times randomly. Is this anything wrong with the webfarm or the code? Note that the webmethod has simple straighfarward insert and update statements.
View 1 Replies
Oct 27, 2010
I have create user wizard control and i put validation control for all field but when i close user control that validators dint clear in firefox or but clear in IE
View 3 Replies
Mar 8, 2011
I am confused about the constructor of ObjectContext
// Summary:
// Initializes a new instance of the System.Data.Objects.ObjectContext class
// with a given connection string and entity container name.
//
// Parameters:
// connectionString:
// The connection string, which also provides access to the metadata information.
//
// defaultContainerName:
// The name of the default entity container. When the defaultContainerName is
// set through this method, the property becomes read-only.
protected ObjectContext(string connectionString, string defaultContainerName);
I am not understanding the parameters clearly.
View 3 Replies
Mar 3, 2011
im working with a proyect made in ASP.Net using Webforms. Im using Entity Framework to save data on Microsoft SQL.
My question is:
Is posible to use a Static class to keep the ObjectContext of EF live and put/get entities NOT saved inside the ObjectContext??
I wan to create an Object, then added with AddObject on the ObjectContext, But NOT to do the Savechanges. All this in one webform An then, in other webform, access to the ObjectContext and Get the Object added
View 3 Replies
Oct 29, 2010
I have a page like Order - Order lines. Order represents by some textboxes and ddls, Order lines represents by GridView.
I want to let users add order lines without save changes to database. For example: he adds 4 order lines, fill order info and then hits Save button. Only an that moment all information should be saved to DB.
When I use code like
using (Entities ctx = new Entities())
{
//create new OrderLine
OrderLine ol = OrderLine.CreateOrderLine(1, 1, "", 1);
//add OrderLine to OrderLines collection
ctx.CreateOrderLines.AddObject(ol);
}
newly created OrderLine does not appears in my object context, so I can't access it and bind GridView to new OrderList collection.
How can I solve this problem? Or maybe there are another ways to perform this task?
View 1 Replies
Apr 4, 2011
I'm building an application using MVC 3 and Entity Framework 4. I've created my Entity Data Model and generated a database from it. Now I know the validation attributes such as [Required] or [StringLength(5)] can be used on the model properties to provide validation both clientside and serverside.
I would like to know if these attributes can also be generated dynamically instead of having to add them to the model explicitly? I saw that in EF 4.1 RC you can make use of the Fluent API to further configure your model in the OnModelCreating method by using the DbModelBuilder class. As shown here I'm working with a framework however that still uses ObjectContext instead of DbContext so I would like to know if the above solution can be used in combination with ObjectContext?
As a final note, since I've been trying to figure out how to generate and use data annotations it seems using view models would increase the complexity of validation. From what I read here it seems that just passing the models directly to the view would remove the need to add annotations to the models as well as the view models. However that means that you can no longer use strongly typed views when you do joins on the models and pass those to the view directly?
View 1 Replies
Apr 27, 2010
I'm learning EF now and have a question regarding the ObjectContext: Should I create instance of ObjectContext for every query (function) when I access the database? Or it's better to create it once (singleton) and reuse it? Before EF I was using enterprise library data access block and created instance of dataacess for DataAccess function...
View 5 Replies
May 19, 2010
If I create a new EDMX model and then I import a function, then I can see my function generated in the Designer. If I perform the same process but I add a T4 template (for Self-Tracking Entities) then I loose the function definition, although TT file has code adding a region named "Function Imports". Is this a bug or am I performing something wrong?
View 1 Replies
Jan 6, 2011
Here's what I want to do:
UI layer: An ASP.NET webforms website.
BLL: Business logic layer which calls the repositories on DAL.
DAL: .EDMX file (Entity Model) and ObjectContext with Repository classes which abstract the CRUD operations for each entity.
Entities: The POCO Entities. Persistence Ignorant. Generated by Microsoft's ADO.Net POCO Entity Generator.
I'd like to create an obejctcontext per HttpContext in my repositories to prevent performance/thread [un]safety issues.
public MyDBEntities ctx
{
get
{
string ocKey = "ctx_" + HttpContext.Current.GetHashCode().ToString("x");
if (!HttpContext.Current.Items.Contains(ocKey))
HttpContext.Current.Items.Add(ocKey, new MyDBEntities ());
return HttpContext.Current.Items[ocKey] as MyDBEntities ;
}
}
I don't want to access HttpContext in my DAL (Where the repositories are located). But I have to somehow pass HttpContext to DAL. based on the answer to my question here, I have to use IoC pattern.
View 1 Replies
Mar 19, 2011
I have this view:
@model MatchGaming.Models.ProfileQuery
@{
ViewBag.Title = "Index";
[code]...
View 2 Replies
Jan 5, 2011
What is difference between Session.Clear() vs. Session.Contents.Clear()?
I want to clear all the Session variables.
View 1 Replies
Mar 30, 2011
I have a doubt concerning the Entity Framework in .NET.
I have a simple ASP .NET web page that has to insert some data in SQL Server with this function:
[code]....
The good news is that the code that Insert function encapsulates I can move it to the place which is called. So my question is: What if there is a place in which I would be forced to call the function? How then I could avoid the error. Passing the parameter as reference (I tried and did not work).
View 2 Replies
Oct 29, 2010
i want to save a IQueryable in cache like this:
[Code]....
However when i try to retreive it and use it i get this error: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
View 5 Replies
Feb 16, 2011
[Code]....
When I want to get the output values its okay but I also want returning a table as a result data.But Datareader has no rows.is it possible if I want a returning query result and multiple output values togather ?I wrote a test above.I can get output values as sqlparameters. But Datareader attached to a Gridview is empty.can you detect whats wrong here and it doesnt return a query result.So stored procedure is not standart or ı am doing something wrong.this doesnt raise any exception.but not returning any data.
[code]....
View 8 Replies
Jun 7, 2010
I want to define a route that have 2 optional parameters in the middle of the URL the start an end parameters are digits
[Code].....
View 1 Replies
Dec 10, 2010
Since ASP.NET MVC3 RC2 I encounter a bug when posting values to a controller method of which one of the parameter is a nullable int. Steps to reproduce:
I've created a test method
[code]....
In MVC3 RC1 this was working without any problems with the nullable int
Update:
I don't seem to have the problem with a newly created MVC3 website. What could I have in my project that influence model binding to nullable int's? And why would there be a difference between RC1 and RC2?
View 10 Replies
May 12, 2010
I am using jquery ajax method on my aspx page,which will invoke the webmethod in the code behind.Currently the webmethod takes a couple of parameters like firstname,lastname,address etc which I am passing from jquery ajax method using
data:JSON.stringify({fname:firstname,lname:lastname,city:city})
now my requirement has been changed such that,the number and type of parameters that are going to be passed is not fixed for ex.parameter combination can be something like fname,city or fname,city or city,lname or fname,lname,city or something else.So the webmethod should be such that it should accept any number parameters.I thought of using arrays to do so, as described here.
But I do not understand how can I identify which and how many parameters have been passedto the webmethod to insert/update the data to the DB.
View 4 Replies
Jan 21, 2010
here is my code for selectiong some records from db table
string strSql = "select * from mtblNBD where SentTo=@SentTo and InternalStatus Is NULL order by DeadLine desc";
SqlCommand com = new SqlCommand(strSql, con);
com.Parameters.Add("@SentTo", SqlDbType.NVarChar, 50).Value = (string)Session["uname"];
here I am using parameters for SenTo field but not for NULL so it is ok... or should I use parameters for this field where value is NULL , if yes then how can I use parameter for this
View 8 Replies
Feb 18, 2010
I have a SOAP web service and I'm trying to figure how to save/log the last 10 requests for each user. Each user is required to send their user/pass in each request, so it's easy to know who the request originated from. With these last 10 requests saved, my goal is to develop some sort of page that will allow them to log-in with their credentials and view the raw request, the actual SOAP message, http header information, and anything relevant that I can think of.
The point is to allow people to troubleshoot their own connection issues instead of having to contact me each time they can't connect, have trouble formatting their request, etc....
My first thought was to store all this information in memory in a hashtable or something, but that may have scalability issues when we have hundreds/thousands of users hitting the web service.
We could use our database to store these requests. Instead of hitting the database each time, I may need to create some "buffer" mechanism that will only update the database after the buffer gets to a certain number of requests. Is there an existing library or mechanism that will do this?
We can't store these requests on the file system on the machine hosting the web service. Since these requests can potentially contain sensitive information, it's a business decision that I'll need to work around. Or maybe there's a better way to achieve what I'm trying to do?
View 2 Replies
Jul 29, 2010
Are web service calls synchronous or asynchronous by default? How is synchronicity determined, by the service or by the client?
I have code similar to the following:
try
{
string result = MakeWebServiceCall_1(); // this is a third party webservice
[code]....
In the above, SetStatus is writing to the same tables that the third party web services read from. If I change the status before both web service calls have completed, it's going to make a big mess and I'm going to get fired. How do I know/ensure that the webservice calls are synchronous?
View 1 Replies