Following code is demonstrating problem with editing existing orders
Line os.ApplyChanges(order2); is throwing System.AggregateException with no errors included. Event log is also empty on the server.
Could you please advice on how to resolve this issue? At this time it looks more like a bug.
private static void Test()
{
NetworkCredential creds = new NetworkCredential();
using (SelectServer ss = new SelectServer(new Uri("http://server"), creds))
{
string reason;
if (!ss.TryAuthenticate(out reason))
{
// Write login failure reason to console and exit.
return;
}
// Fetch a new order from the order store.
IOrderStore os = ss.GetService<IOrderStore>();
IOrder order = os.NewOrder();
// Cast to dynamic to make order handling easier.
dynamic o = (dynamic)order;
// Set a property.
o.Project = "New Deal";
var orderNumber = (string)o.Number;
// Save the order in the database.
os.ApplyChanges(order);
IOrderInfo search = os.Orders.Where(t => t.Number == orderNumber).FirstOrDefault();
if (search != null)
{
// Open found order.
using (IOrder order2 = os.OpenOrder(search, false))
{
try
{
dynamic dynamicOrder = (dynamic)order2;
os.ApplyChanges(order2);
}
finally
{
os.CloseOrder(order2);
}
}
}
else
{
throw new Exception(string.Format("Order number {0} not found", orderNumber));
}
}
}
Failing to Edit existing order
-
- Posts: 1377
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Failing to Edit existing order
You must close the first order before attempting to write changes to it as order2.
When you open an order, you have an exclusive write lock on it until it is closed. Your order2 can open the same order on the server, but fails attempting to write to the server since it does not have write access.
When you open an order, you have an exclusive write lock on it until it is closed. Your order2 can open the same order on the server, but fails attempting to write to the server since it does not have write access.
Bob Richards, Senior Software Developer, SoftPro
-
- Posts: 8
- Joined: Fri Oct 10, 2014 2:45 pm
Re: Failing to Edit existing order
Hello Bob,
Thank you for response. We made change based on yours recommendations. Unfortunately, processing is still failing with same error.
Could you please take a look?
We are using version 3.1.20617.9. Source code is below.
private static void Test()
{
NetworkCredential creds = new NetworkCredential();
using (SelectServer ss = new SelectServer(new Uri("http://server"), creds))
{
string reason;
if (!ss.TryAuthenticate(out reason))
{
// Write login failure reason to console and exit.
return;
}
string orderNumber;
// Fetch a new order from the order store.
IOrderStore os = ss.GetService<IOrderStore>();
using(IOrder order = os.NewOrder())
{
try
{
// Cast to dynamic to make order handling easier.
dynamic o = (dynamic)order;
// Set a property.
o.Project = "New Deal";
orderNumber = (string)o.Number;
// Save the order in the database.
os.ApplyChanges(order);
}
finally
{
os.CloseOrder(order);
}
}
IOrderInfo search = os.Orders.Where(t => t.Number == orderNumber).FirstOrDefault();
if (search != null)
{
// Open found order.
using (IOrder order2 = os.OpenOrder(search, false))
{
try
{
dynamic dynamicOrder = (dynamic)order2;
os.ApplyChanges(order2);
}
finally
{
os.CloseOrder(order2);
}
}
}
else
{
throw new Exception(string.Format("Order number {0} not found", orderNumber));
}
}
}
Thank you for response. We made change based on yours recommendations. Unfortunately, processing is still failing with same error.
Could you please take a look?
We are using version 3.1.20617.9. Source code is below.
private static void Test()
{
NetworkCredential creds = new NetworkCredential();
using (SelectServer ss = new SelectServer(new Uri("http://server"), creds))
{
string reason;
if (!ss.TryAuthenticate(out reason))
{
// Write login failure reason to console and exit.
return;
}
string orderNumber;
// Fetch a new order from the order store.
IOrderStore os = ss.GetService<IOrderStore>();
using(IOrder order = os.NewOrder())
{
try
{
// Cast to dynamic to make order handling easier.
dynamic o = (dynamic)order;
// Set a property.
o.Project = "New Deal";
orderNumber = (string)o.Number;
// Save the order in the database.
os.ApplyChanges(order);
}
finally
{
os.CloseOrder(order);
}
}
IOrderInfo search = os.Orders.Where(t => t.Number == orderNumber).FirstOrDefault();
if (search != null)
{
// Open found order.
using (IOrder order2 = os.OpenOrder(search, false))
{
try
{
dynamic dynamicOrder = (dynamic)order2;
os.ApplyChanges(order2);
}
finally
{
os.CloseOrder(order2);
}
}
}
else
{
throw new Exception(string.Format("Order number {0} not found", orderNumber));
}
}
}