<?xml version="1.0" encoding="iso-8859-1" ?><!-- Created on the 5/26/2013 1:05:32 AM. Opf3 powered. --><rss version="0.91"><channel><title>Opf3 Forum:  There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com</link><description></description><language>en-US</language><item><pubDate>Mon, 4 Dec 2006 4:30:24 PM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=728</link><description><![CDATA[Hi,<br/><br/>the transaction is always rolled back on the storage if no commit comes in and the connection is closed. This happens always if an error occured. Your transaction is always rolled back!<br/><br/>You need to pass the persistent object type to do the reload of the persistent objects. This is at this stage the only way to do it. The problem is that Opf3 does a reload before save. This happens to detect concurrency problems. At the current implementation you would need to do an persistchanges for the different objects types in your objectset.<br/><br/>Are you saving here a bunch of different objects or all of the same type?]]></description></item><item><pubDate>Mon, 4 Dec 2006 12:17:39 PM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=726</link><description><![CDATA[Problem Located....<br/><br/>The Exception is not the original source exception.  <br/>The exception being thrown is in AttributeTypeMappingProvider<br/><br/>throw new MappingException(string.Format("Cannot create mapping for type '{0}' without persistent attribute.", type.FullName));<br/><br/>The exception is being passed up through various catch blocks until it reaches my code<br/><br/>public BusinessTransactionData PersistChanges(BusinessTransactionData objects)<br/>        {<br/>            ObjectContext context = CreateObjectContext();<br/>            ObjectSet<object> objs = new ObjectSet<object>();<br/>            foreach (object obj in objects.Data)<br/>            {<br/>                objs.Add(obj);<br/>            }<br/>            Transaction transaction = context.StartTransaction();<br/>                try<br/>                {<br/>                    context.PersistChanges(objs);<br/>                    transaction.Commit();<br/>                    return objects;<br/>                }<br/>                catch (Exception)<br/>                {<br/>                    transaction.Rollback();<br/>                    throw;<br/>                }<br/>            <br/>        }<br/><br/>where the transaction.RollBack() in the catch block causes the DataReader Exception.<br/>This is a problem as rolling back the transaction in case of an error is pretty important.<br/><br/>So my other problem is in the type mapping as the business object is being passed as object rather then its type.  Is there anyway I can get around this.<br/><br/>Thanks<br/>]]></description></item><item><pubDate>Mon, 4 Dec 2006 10:02:28 AM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=725</link><description><![CDATA[No Change with the latest build.]]></description></item><item><pubDate>Thu, 30 Nov 2006 4:41:53 PM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=702</link><description><![CDATA[I could send you the most recent build, if you want. Could you send an e-mail to support@chilisoftware.net<br/><br/>Thank you<br/>Christian]]></description></item><item><pubDate>Thu, 30 Nov 2006 4:40:56 PM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=701</link><description><![CDATA[Using SqlServer 2005]]></description></item><item><pubDate>Thu, 30 Nov 2006 4:37:09 PM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=700</link><description><![CDATA[Forget my last message. It should work anyway. Wow, this is weird.<br/><br/>Christian]]></description></item><item><pubDate>Thu, 30 Nov 2006 4:35:26 PM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=699</link><description><![CDATA[The <object> generic could also cause the problem. Opf3 is doing a reload before doing an update. The code looks like this:<br/><br/></p><div class="ForumCode">using (ObjectReader<T> reader = e.Context.GetObjectReader<T>(ObjectExpression.CreateLoadExpression(obj)))<br/>{<br/></div><p><br/>This T you are seeing here, is the <object> you used in your code. This causes Opf3 to crash. But it's strange that you get this exception you should get another one.<br/><br/>Anyway you need to specify here the type that is persisted. Opf3 will have problems otherwise.<br/><br/>Christian<br/>]]></description></item><item><pubDate>Thu, 30 Nov 2006 4:33:04 PM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=698</link><description><![CDATA[Are you sure you have no ObjectReader open somewhere in your app, while doing the operation? This happens usually if an ObjectReader is open. An ObjectReader holds an active connection to the database, since it is a cursor.<br/><br/>What's the DB you are using?<br/><br/>Christian]]></description></item><item><pubDate>Thu, 30 Nov 2006 4:22:00 PM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=697</link><description><![CDATA[The only real different I really see is in the routine that works the object is being passed as what it is , while in the one that doesn't its being passed as object.]]></description></item><item><pubDate>Thu, 30 Nov 2006 4:10:56 PM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=696</link><description><![CDATA[Sorry forgot one piece of information. The error only happens if the object is being being updated (doesnt happen for first saves).  I think the error is thrown when the object is being re-read from the database.]]></description></item><item><pubDate>Thu, 30 Nov 2006 3:38:23 PM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=695</link><description><![CDATA[I dont know , in theory they should be the same.<br/>The second is done because I want to save several objects in the same database transaction, but in the example given there is only one object in the list.<br/><br/>The same is happening with any object I throw at this method.]]></description></item><item><pubDate>Thu, 30 Nov 2006 3:32:45 PM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=694</link><description><![CDATA[Wow! Gets even stranger... The second code is working or not? What's, from your standpoint the difference, that makes it work?<br/><br/>Christian]]></description></item><item><pubDate>Thu, 30 Nov 2006 3:24:01 PM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=693</link><description><![CDATA[The object being Saved<br/><br/>using System;<br/>using System.Collections.Generic;<br/>using BusinessObjects.Data;<br/>using Chili.Opf3;<br/><br/>namespace JobControl.BusinessObjects.Data<br/>{<br/>    [Serializable]<br/>    [Persistent("Kit")]<br/>    public class KitData : BusinessObjectData<br/>    {<br/>        public KitData()<br/>        {<br/>        }<br/><br/>        #region Fields<br/><br/>        private string _name;<br/>        private Guid _kitTypeId;<br/><br/>        #endregion<br/><br/>        #region Properties<br/><br/>        /// <summary><br/>        /// This property is mapped to the "Name" field. Length must be between 0 and 100 characters. Mandatory.<br/>        /// </summary><br/>        [Field("Name", AllowDBNull = false)]<br/>        public string Name<br/>        {<br/>            get { return _name; }<br/>            set<br/>            {<br/>                if (value == null)<br/>                    throw new ArgumentNullException("value", "Value is null.");<br/>                if (value != null && value.Length > 100)<br/>                    throw new ArgumentException("Value length must be between 0 and 100 characters.");<br/><br/>                _name = value;<br/>            }<br/>        }<br/><br/>        /// <summary><br/>        /// The foreign key connected with another persistent object.<br/>        /// </summary><br/>        [Field("KitTypeId", AllowDBNull = false)]<br/>        public Guid KitTypeId<br/>        {<br/>            get { return _kitTypeId; }<br/>            set { _kitTypeId = value; }<br/>        }<br/>        #endregion<br/><br/>        public static List<KitData> LoadForDabTask(Guid id)<br/>        {<br/>            return new List<KitData>(BusinessObjectServerClient.Server.LoadFromQuery<KitData>(<br/>                                                 Properties.Resources.SQLKikDataLoadForDabTask,<br/>                                                 id));<br/>        }<br/><br/>        public static List<KitData> LoadForMetalTask(Guid id)<br/>        {<br/>            return new List<KitData>(BusinessObjectServerClient.Server.LoadFromQuery<KitData>(<br/>                                                 Properties.Resources.SQLKikDataLoadForMetalTask,<br/>                                                 id));<br/>        }<br/><br/>        public static List<KitData> LoadForScrewFixTask(Guid id)<br/>        {<br/>            return new List<KitData>(BusinessObjectServerClient.Server.LoadFromQuery<KitData>(<br/>                                                 Properties.Resources.SQLKikDataLoadForScrewFixTask,<br/>                                                 id));<br/>        }<br/><br/>        public static List<KitData> LoadForTapeTask(Guid id)<br/>        {<br/>            return new List<KitData>(BusinessObjectServerClient.Server.LoadFromQuery<KitData>(<br/>                                                 Properties.Resources.SQLKikDataLoadForTapeTask,<br/>                                                 id));<br/>        }<br/>    }<br/>}<br/><br/>The Call Stack<br/><br/>	Chili.Opf3.dll!Chili.Opf3.Storages.SqlStorageBase.ExecuteReader<object>(Chili.Opf3.ObjectContext context = {Chili.Opf3.ObjectContext}, Chili.Opf3.Query.IQuery query = {Chili.Opf3.Query.ObjectExpression}) Line 131	C#<br/> 	Chili.Opf3.dll!Chili.Opf3.Storages.MsSql.MsSqlStorage.ExecuteReader<object>(Chili.Opf3.ObjectContext context = {Chili.Opf3.ObjectContext}, Chili.Opf3.Query.IQuery query = {Chili.Opf3.Query.ObjectExpression}) Line 183 + 0x34 bytes	C#<br/> 	Chili.Opf3.dll!Chili.Opf3.ObjectContext.GetObjectReader<object>(Chili.Opf3.Query.IQuery query = {Chili.Opf3.Query.ObjectExpression}) Line 673 + 0x44 bytes	C#<br/> 	Chili.Opf3.dll!Chili.Opf3.Concurrency.Md5.Md5ConcurrencyManager.OnBeforeUpdate<object>(object obj = {JobControl.BusinessObjects.Data.KitData}, Chili.Opf3.Concurrency.ConcurrencyManagerEventArgs e = {Chili.Opf3.Concurrency.ConcurrencyManagerEventArgs}) Line 53 + 0x47 bytes	C#<br/> 	Chili.Opf3.dll!Chili.Opf3.ObjectPersister.Update<object>(object obj = {JobControl.BusinessObjects.Data.KitData}, Chili.Opf3.ObjectInfo objectInfo = {Chili.Opf3.ObjectInfo}, Chili.Opf3.PersistDepths persistDepth = FullObjectGraph) Line 264 + 0x40 bytes	C#<br/> 	Chili.Opf3.dll!Chili.Opf3.ObjectPersister.PersistChanges<object>(object obj = {JobControl.BusinessObjects.Data.KitData}, Chili.Opf3.PersistDepths persistDepth = FullObjectGraph) Line 116 + 0x54 bytes	C#<br/> 	Chili.Opf3.dll!Chili.Opf3.ObjectContext.PersistChanges<object>(object obj = {JobControl.BusinessObjects.Data.KitData}, Chili.Opf3.PersistDepths persistDepth = FullObjectGraph) Line 1715 + 0x3b bytes	C#<br/> 	Chili.Opf3.dll!Chili.Opf3.ObjectSet<object>.Persist(Chili.Opf3.ObjectContext context = {Chili.Opf3.ObjectContext}, Chili.Opf3.PersistDepths persistDepth = FullObjectGraph, Chili.Opf3.PersistingTrace persistingTrace = {Chili.Opf3.PersistingTrace}) Line 1456 + 0x3d bytes	C#<br/> 	Chili.Opf3.dll!Chili.Opf3.ObjectSet<object>.Chili.Opf3.ICustomPersister.Persist(Chili.Opf3.ObjectContext context = {Chili.Opf3.ObjectContext}, Chili.Opf3.PersistDepths persistDepth = FullObjectGraph, Chili.Opf3.PersistingTrace persistingTrace = {Chili.Opf3.PersistingTrace}) Line 1409 + 0x12 bytes	C#<br/> 	Chili.Opf3.dll!Chili.Opf3.ObjectContext.PersistChanges<Chili.Opf3.ObjectSet<object>>(Chili.Opf3.ObjectSet<object> obj = {Chili.Opf3.ObjectSet`1[System.Object], Count = 1, RemovedList.Count = 0}, Chili.Opf3.PersistDepths persistDepth = FullObjectGraph) Line 1687 + 0x15 bytes	C#<br/> 	Chili.Opf3.dll!Chili.Opf3.ObjectContext.PersistChanges<Chili.Opf3.ObjectSet<object>>(Chili.Opf3.ObjectSet<object> obj = {Chili.Opf3.ObjectSet`1[System.Object], Count = 1, RemovedList.Count = 0}) Line 1631 + 0x30 bytes	C#<br/> 	BusinessObjects.Data.dll!BusinessObjects.Data.BusinessObjectServer.PersistChanges(BusinessObjects.Data.BusinessTransactionData objects = {BusinessObjects.Data.BusinessTransactionData}) Line 185 + 0xd bytes	C#<br/> 	BusinessObjects.dll!BusinessObjects.BusinessTransaction.Save() Line 118 + 0x15 bytes	C#<br/> 	JobControl.Surveyor.dll!JobControl.Surveyor.KitController.Save() Line 103 + 0xa bytes	C#<br/> 	JobControl.Surveyor.dll!JobControl.Surveyor.KitView._btnOK_Click(object sender = {Janus.Windows.EditControls.UIButton}, System.EventArgs e = {X = 22 Y = 13 Button = Left}) Line 50 + 0x10 bytes	C#<br/> 	System.Windows.Forms.dll!System.Windows.Forms.Control.OnClick(System.EventArgs e) + 0x57 bytes	<br/> 	Janus.Windows.UI.v3.dll!Janus.Windows.EditControls.UIButton.OnClick(System.EventArgs e = {X = 22 Y = 13 Button = Left}) + 0xa1 bytes	<br/> 	System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m = {msg=0x202 (WM_LBUTTONUP) hwnd=0x20dda wparam=0x0 lparam=0xd0016 result=0x0}, System.Windows.Forms.MouseButtons button = Left, int clicks = 1) + 0x166 bytes	<br/> 	System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x544 bytes	<br/> 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0xd bytes	<br/> 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0xd6 bytes	<br/> 	System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 514, System.IntPtr wparam, System.IntPtr lparam) + 0x75 bytes	<br/> 	[Native to Managed Transition]	<br/> 	[Managed to Native Transition]	<br/> 	System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) + 0x2ea bytes	<br/> 	System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x17d bytes	<br/> 	System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x53 bytes	<br/> 	System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x2e bytes	<br/> 	JCS.exe!JCS.Program.Main() Line 26 + 0x7 bytes	C#<br/> 	[Native to Managed Transition]	<br/> 	[Managed to Native Transition]	<br/> 	mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x32 bytes	<br/> 	Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2b bytes	<br/> 	mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x3b bytes	<br/> 	mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x81 bytes	<br/> 	mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x40 bytes	<br/>]]></description></item><item><pubDate>Thu, 30 Nov 2006 3:13:58 PM GMT</pubDate><title>RE: There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=692</link><description><![CDATA[This is a weird exception, as Opf3 does dispose all ObjectReader (or IDataReader) immediately after using them.<br/><br/>Could you post the stack trace?<br/><br/>Thanks<br/>Christian]]></description></item><item><pubDate>Thu, 30 Nov 2006 2:59:53 PM GMT</pubDate><title> There is already an open DataReader associated with this command problem</title><link>http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=1&amp;Topic=691</link><description><![CDATA[public BusinessTransactionData PersistChanges(BusinessTransactionData objects)<br/>        {<br/>            ObjectContext context = CreateObjectContext();<br/>            ObjectSet<object> objs = new ObjectSet<object>();<br/>            foreach (object obj in objects.Data)<br/>            {<br/>                objs.Add(obj);<br/>            }<br/>            Transaction transaction = context.StartTransaction();<br/>                try<br/>                {<br/>                    context.PersistChanges(objs);<br/>                    transaction.Commit();<br/>                    return objects;<br/>                }<br/>                catch (Exception)<br/>                {<br/>                    transaction.Rollback();<br/>                    throw;<br/>                }<br/>            <br/>        }<br/><br/>when saving using the above code I get a "there is already an open DataReader associated with this command"  This happens even with a single object in the collection.<br/><br/>I am guessing it is the transaction causing this.<br/><br/>if I save the same object with the following code<br/><br/>public T PersistChanges<T>(T obj, bool createTransaction)<br/>        {<br/>           <br/>            ObjectContext context = CreateObjectContext();<br/>            Transaction transaction = null;<br/>            if (createTransaction)<br/>                transaction = context.StartTransaction();<br/><br/>            try<br/>            {<br/>                context.PersistChanges(obj);<br/>                if (createTransaction)<br/>                    transaction.Commit();<br/>                return obj;<br/>            }<br/>            catch (Exception)<br/>            {<br/>                if (createTransaction)<br/>                    transaction.Rollback();<br/>                throw;<br/>            }<br/>        }<br/><br/>all is fine.<br/><br/>Any Suggestions<br/>]]></description></item></channel></rss>