Tuesday, April 19, 2011

System.Data.Odbc.OdbcException: ERROR [HY000] [DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Failure getting record lock on a record from table PUB.#####.

Solution: Add the no-lock statement to each select statement.

SELECT * FROM PUB.##### WITH(NOLOCK)

Tuesday, April 12, 2011

I was getting a System.ObjectDisposedException when trying to serialize/remote a LINQ result set via a webservice. The actual data result was fine. The problem lay with the parent and child relationships generated by LINQ. Looping through each result and setting all the relationship objects to null stopped the exception, but that was not a solution (merely identified the source of the issue). The solution (provided to me by co-worker: Robert Blasutig), is to prevent LINQ from trying to load parent and child relationships automatically.

This is done by setting the DeferredLoadingEnabled property of the context to false.

To then have LINQ load parent/child objects later, you must specify which relationships to load with the following:

using (ClientDBDataContext clientCtx = new ClientDBDataContext(clientDbConnStr))
{
clientCtx.DeferredLoadingEnabled = false;

DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith(dtAlias => dtAlias.ParentChildTableName);
clientCtx.LoadOptions = loadOptions;

...query...
}

FULL EXCEPTION:

System.InvalidOperationException: There was an error generating the XML document. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'DataContext accessed after Dispose.'.
at System.Data.Linq.DataContext.GetTable(Type type)
at System.Data.Linq.CommonDataServices.GetDataMemberQuery(MetaDataMember member, Expression[] keyValues)
at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.ExecuteKeyQuery(Object[] keyValues)
at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.Execute(Object instance)
at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.DeferredSource.GetEnumerator()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at System.Data.Linq.EntityRef`1.get_Entity()
at AparcSystems.AparcDataAccess.Aparc_PdmTariff.get_Aparc_EnfArea()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write25_Aparc_PdmTariff(String n, String ns, Aparc_PdmTariff o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write57_ArrayOfAparc_PdmTariff(Object o)
at Microsoft.Xml.Serialization.GeneratedAssembly.ListOfAparc_PdmTariffSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()

Monday, April 11, 2011

"DoInsertLogbookRecord"
"DoInsertTransLogRecord"

"Transaction context in use by another session"

Trigger code updates a table in a database in local instance. Does not require (ie CANNOT HAVE) reference to [server\instance] name in target.