I am trying to pass a SqlGeometry type to a stored procedure using Simple.Data and SQL Server 2008. The stored procedure definition looks like this:
CREATE PROCEDURE [dbo].[spUpdateDamLocation]
(
#DamID int,
#Shape geometry
)
The call I am using for Simple.Data looks like this:
var db = Simple.Data.Database.OpenConnection(dbConn);
db.spUpdateDamLocation(DamID: damLocation.DamID, Shape: damLocation.Shape);
Where dbConn is a connection string, damLocation.DamID is an integer and damLocation.Shape is a SqlGeometry object.
The error I am getting is:
System.ArgumentException: UdtTypeName property must be set for UDT parameters.
at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
at System.Data.SqlClient.SqlCommand.SetUpRPCParameters(_SqlRPC rpc, Int32 startCount, Boolean inSchema, SqlParameterCollection parameters)
at System.Data.SqlClient.SqlCommand.BuildRPC(Boolean inSchema, SqlParameterCollection parameters, _SqlRPC& rpc)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at Simple.Data.Ado.DbCommandExtensions.TryExecuteReader(IDbCommand command)
at Simple.Data.Ado.ProcedureExecutor.ExecuteReader(IDbCommand command)
at Simple.Data.Ado.ProcedureExecutor.Execute(IDictionary`2 suppliedParameters, IDbTransaction transaction)
at Simple.Data.Ado.ProcedureExecutor.Execute(IDictionary`2 suppliedParameters)
at Simple.Data.Ado.AdoAdapter.Execute(String functionName, IDictionary`2 parameters)
at Simple.Data.Database.ExecuteFunction(Object& result, ExecuteFunctionCommand command)
at Simple.Data.DataStrategy.TryInvokeFunction(String functionName, Func`1 getFunctionArguments, Object& result)
at Simple.Data.DataStrategy.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
at CallSite.Target(Closure , CallSite , Object , Int32 , SqlGeometry )
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3[T0,T1,T2](CallSite site, T0 arg0, T1 arg1, T2 arg2)
Is there a way to specify a specific UDT of the parameter in Simple.Data? If I were just using ADO.NET I would do something like this:
SqlParameter sqlParam = sqlCmd.Parameters.Add("#Shape", SqlDbType.UDT);
sqlParam.UdtTypeName = "geometry";
sqlParam.Value = myTypeOfSqlGeometry;
Simple.Data doesn't currently handle user-defined types at the moment. Issue 163 on github raised a similar question several months ago as encountering a UDT crashed the SqlSchemaProvider. The bug was fixed but it doesn't look like there has been any further development into supporting SqlGeometry, SqlGeography and the like.
A stored procedure, as your're trying would seem to be the best way to go, but as UDTs aren't explicitly supported, perhaps sending the SqlGeometry object as its WKT literal equivalent with a call to ToString() would work?
var db = Simple.Data.Database.OpenConnection(dbConn);
db.spUpdateDamLocation(DamID: damLocation.DamID, Shape: damLocation.Shape.ToString());
Also, With Simple.Data v1 just around the corner, I'd suggest opening a new issue for UDT support to be added in v1.1 so you don't need to go through such hoops in the future.
Related
I created a new composite entity based on two new entities. Those in turn are based on new views, which are based on new queries. The queries are based on a mix of standard tables and views and custom tables.
Similar composite entities were created in the past and work.
When exporting the composite entity with a data project, I'm getting the following exceptions:
Exception in AX-DIXFRuntime event log:
System.Exception: Incorrect syntax near the keyword 'FROM'.
at Microsoft.Dynamics.AX.Framework.Tools.DMF.ServiceProxy.DmfEntitySharedTypesProxy.DoWork[T](Func`1 work)
at Dynamics.AX.Application.DMFGenerateSSISPackage.`generateFileDataV2(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution, String _defGroupName, DMFFileFormat _fileFormat, DMFDelimiter _rowDelimiter, DMFDelimiter _columnDelimiter, String _codePage, String _locale, NoYes _isFirstRowHeader, NoYes _unicode, String _source, String _textQualifier, DMFXMLStyle _style, String _rootElement, String _filePath, Map _entitySyncVersion, Int32 _previewCount, Boolean #_entitySyncVersion_IsDefaultSet, Boolean #_previewCount_IsDefaultSet) in xppSource://Source/ApplicationFoundation\AxClass_DMFGenerateSSISPackage.xpp:line 1419
Exception in AX-DIXFSSISRuntime event log:
SSISexceptionMessage System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'FROM'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
at Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelper.DMFCompositeEntity.GetDatasetForXMlExport(String stagingString)
at Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelper.DMFCompositeEntity.ExportCompositeEntityToXML()
at Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelperService.Service.ServiceHelper.ExportCompositeEntityToXML(DMFCompositeEntity dmfCompEnt) ClientConnectionId:9a234a11-809d-4d88-828d-8981bfb4faa8 Error Number:156,State:1,Class:15
What I've tried so far:
refresh the entities and composite entity with en-us language setting
debug DMFGenerateSSISPackage.generateFileDataV2 and compare with the export of a working composite entity > no obvious incorrect differences found
remove line entity from the composite entity > same issue
export header/line entity directly > works without issue
Question
My question is if there is a way to find out what the SQL is that caused the Incorrect syntax near the keyword 'FROM' exception. If there is no way, I'm happy to hear suggestions how I can further narrow down this issue.
The issue is caused by the length of the label text of the composite entity and the length of the entity names. They must not exceed a limit of 99 characters.
Assume that you have two entities with names
VeryLongNameWithSixtyCharactersThatIdentifyTheFirstEntity123 (60 characters)
AnotherLongNameWithSeventyCharactersThatIdentifyTheSecondEntity1234567 (70 characters)
Also assume that the label text of your entity is the following
Label text with 30 characters1
If you navigate to workspace Data management and open the list of entities, find the composite entity named Label text with 31 characters1 and open "Child entities".
It will show 2 entries named
Label text with 30 characters1_VeryLongNameWithSixtyCharactersThatIdentifyTheFirstEntity123 (90 characters)
Label text with 30 characters1_AnotherLongNameWithSeventyCharactersThatIdentifyTheSecondEntity1234567 (100 characters)
This composite entity will export correctly.
But if you add another character to the name of the second entity, the second entry of the child entities will have 101 characters. This will cause the described exception error.
Fix by Microsoft
In issue 2086 of the Microsoft documentation, they announced to introduce a check during compile time for this in PU 36 which is currently under investigation. See KB4549600.
Overview
This is a strange error which has not googled well.
I attempt to create and insert an AssetOwner record. But I receive the error "System.Data.SqlClient.SqlException" due to a foreign key relationship on two tables that (apparently) have nothing to do with the SQL statement I'm attempting:
The INSERT statement conflicted with the FOREIGN KEY constraint
"FK_Adjustments_AdjustmentProcesses". The conflict occurred in
database "TPS_2", table "dbo.AdjustmentProcesses", column 'ID'. The
statement has been terminated.
Details
Here is the code snippet where the error is thrown (indicated by the comment) ("da" is just like a repository):
var add = new AssetOwner()
{
Client = da.Clients.Get(adjustment.ToClientID),
Asset = da.Assets.Get(adjustment.AssetID),
StartDate = adjustment.EffectiveDate
};
da.AssetOwners.Add(add);
var remove = da.AssetOwners.GetCurrentOwner(da.Assets.Get(adjustment.AssetID));
remove.EndDate = adjustment.EffectiveDate;
da.SaveChanges(); // Exception here (this is DataContext.SubmitChanges())
A small picture of the tables and relationships relevant here:
The relationship throwing the error has been highlighted red, the table in question has been circled in red - as you can see, an insert of the AssetOwner doesn't appear to have much to do with the Adjustment-AdjustmentProcess relationship?
Troubleshooting
I'm using Visual Studio generated LINQ-to-SQL classes, and at times I've noticed strange gremlins in refreshed versions of my DataContext. My first thought was therefore to delete the relationship in question, re-generate, re-create the relationship, re-generate. This has not been successful.
I've stepped through the code a few times - it is notable there are no other SQL statements in the controller action before this one - and I have been unable to see any possible reason for this exception. Nevertheless, I'll reproduce the entire controller action here (hoping the long code snippet won't discourage any potential readers):
public ActionResult ManualEntry(int id, FormCollection collection)
{
// Grab the adjustment process
var process = da.AdjustmentProcesses.Get(id);
// Map a dto and set the details needed for the view
var dto = new AdjustmentProcessViewModel();
Adapter.MapDto(dto, process, da);
Adapter.SetDetails(dto, da);
// Generate the premium values for those policies we can
var pg = new PremiumGenerator(da);
foreach (var apd in dto.AdjustmentPolicyDetails)
{
if (apd.CanAutoGenerate == true)
pg.GeneratePremiumValues(dto.Policies[apd.Index]);
}
// Update the model from the form collection
TryUpdateModel(dto.Policies, "Policies");
// Run Validation
var invalids = 0;
foreach (var apd in dto.AdjustmentPolicyDetails)
{
var policy = dto.Policies[apd.Index];
var validator = new PolicyValidator(da);
validator.Validate(policy);
if (!validator.IsValid)
{
invalids++;
foreach (var ruleViolation in validator.RuleViolations)
apd.RuleViolations.Add(new RuleViolation(ruleViolation.ErrorMessage, "Policies[" + apd.Index.ToString() + "]." + ruleViolation.PropertyName));
this.MergeRuleViolations(apd.RuleViolations);
}
}
// If validation has failed, return the view
if (invalids > 0)
return View(dto);
else // Otherwise process the adjustments
{
foreach (var adjustment in da.Adjustments.GetAdjustmentsForProcess(process.ID))
{
if (adjustment.ActionID == (int)AdjustmentAction.Add)
{
var add = new AssetOwner()
{
Client = da.Clients.Get(adjustment.ClientID),
Asset = da.Assets.Get(adjustment.AssetID),
StartDate = adjustment.EffectiveDate
};
da.AssetOwners.Add(add);
da.SaveChanges();
}
else if (adjustment.ActionID == (int)AdjustmentAction.Remove)
{
var remove = da.AssetOwners.GetCurrentOwner(da.Assets.Get(adjustment.AssetID));
remove.EndDate = adjustment.EffectiveDate;
da.SaveChanges();
}
else if (adjustment.ActionID == (int)AdjustmentAction.Transfer)
{
var add = new AssetOwner()
{
Client = da.Clients.Get(adjustment.ToClientID),
Asset = da.Assets.Get(adjustment.AssetID),
StartDate = adjustment.EffectiveDate
};
da.AssetOwners.Add(add);
var remove = da.AssetOwners.GetCurrentOwner(da.Assets.Get(adjustment.AssetID));
remove.EndDate = adjustment.EffectiveDate;
da.SaveChanges();
}
}
var policyAdapter = new PolicyAdapter();
foreach (var policy in dto.Policies)
{
var newPolicy = new Policy();
policyAdapter.MapObject(newPolicy, policy, da);
var validator = new PolicyValidator(da);
validator.Validate(newPolicy);
if (!validator.IsValid)
throw new Exception();
else
{
da.Policies.Add(newPolicy);
da.SaveChanges();
}
}
}
return RedirectToAction("Index");
}
Perhaps a clue is the fact that the object I'm working on is a "Transfer" (going down that code path) which throws the error, whereas an "Add" or "Remove" both work fine without throwing the error. Still, the code is virtually the same, and all adjustment objects in the DB table satisfy the foreign key constraint.
To further aid troubleshooting, here is the stack trace:
System.Data.SqlClient.SqlException (0x80131904): The INSERT statement
conflicted with the FOREIGN KEY constraint
"FK_Adjustments_AdjustmentProcesses". The conflict occurred in
database "TPS_2", table "dbo.AdjustmentProcesses", column 'ID'. The
statement has been terminated. at
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection) at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj) at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData() at
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,
RunBehavior runBehavior, String resetOptionsString) at
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean
async) at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method, DbAsyncResult result) at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method) at
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
behavior, String method) at
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior
behavior) at
System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query,
QueryInfo queryInfo, IObjectReaderFactory factory, Object[]
parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object
lastResult) at
System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query,
QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[]
userArguments, ICompiledSubQuery[] subQueries) at
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression
query) at
System.Data.Linq.ChangeDirector.StandardChangeDirector.DynamicInsert(TrackedObject
item) at
System.Data.Linq.ChangeDirector.StandardChangeDirector.Insert(TrackedObject
item) at
System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode
failureMode) at
System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at TPS.Models.TPSDataAccess.SaveChanges() in
C:\Users\tim.niven.KJRG\Documents\Visual Studio
2010\Projects\TPS-trunk\TPS\TPS\Models\MainObjects\TPSDataAccess.cs:line
169 at
TPS.Areas.Clients.Controllers.AdjustmentProcessController.ManualEntry(Int32
id, FormCollection collection) in
C:\Users\tim.niven.KJRG\Documents\Visual Studio
2010\Projects\TPS-trunk\TPS\TPS\Areas\Clients\Controllers\AdjustmentProcessController.cs:line
257 at lambda_method(Closure , ControllerBase , Object[] ) at
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext
controllerContext, IDictionary2 parameters) at
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext
controllerContext, ActionDescriptor actionDescriptor, IDictionary2
parameters) at
System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.b__12()
at
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter
filter, ActionExecutingContext preContext, Func1 continuation) at
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext
controllerContext, IList1 filters, ActionDescriptor actionDescriptor,
IDictionary`2 parameters) at
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext
controllerContext, String actionName)
And so I've been banging my head on the table with this one all day - any help or guidance will be greatly appreciated.
Cheers,
Tim.
It was silly in the end (as it often is): it was of course some other bit of code further up in the action, one of the adapter methods was manipulating an object retrieved from the database it shouldn't have been.
Once I isolated the code that was throwing the exception, and it worked, I changed the order of things, and found the exception was thrown not on the insert of the AssetOwner. Therefore, I called DataContext.SubmitChanges() at numerous locations throughout the code to find out where it was causing the problem - found and fixed.
I have an application using the Entity Framework with a SQL Server 2008 (Express) database. I'm getting an intermittent error while doing an update to an entity in the database which indicates that 'the supplied value is not a valid instance of data type float'. However, as best I can tell, the values it's setting will always be floats. They're cast from integers, but even still will always yield floats. If the code did manage to create an invalid float somehow, I would have thought that .NET would complain about it before it even got to SQL Server.
I've included the full exception, code extracts, and schema below.
Is there anything I could be missing here - for example, could a single value be considered a float in .NET but not in SQL Server? Alternatively, is there any way I can programmatically log the precision and scale of a float so that I can diagnose what's going on if the problem comes up again?
I've added some additional logging to try to capture exactly what's going on here, but this is an intermittent problem and I can't reproduce it myself.
The error is:
System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. --->
System.Data.SqlClient.SqlException: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 4 ("#1"): The supplied value is not a valid instance of data type float. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
--- End of inner exception stack trace ---
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Objects.ObjectContext.SaveChanges()
at MyApplication.ImageProcessing.ProcessImage(Image image) in C:\Code\ImageProcessing.cs:line 224
Here's the code that is being executed. (Note that the Image class is the entity class from Entity Framework.)
private static System.Random _randomLocation = new System.Random();
private void ProcessImage(Image image)
{
float x = _randomLocation.Next(668); // note: the System.Random.Next method always returns an int
float y = 0 - image.Height; // note: image.Height is an int and is always around 300-600 in value in this application
image.X = x;
image.Y = y;
_dataContext.SaveChanges();
}
The schema extract for the table that this is referring to is:
CREATE TABLE Image
(
ImageID uniqueidentifier NOT NULL PRIMARY KEY,
X float NOT NULL,
Y float NOT NULL
)
Also I should note that the EF model uses the data type Single for the X and Y columns.
I got this exact same error. It turns out I was dividing a float by zero. This didn't throw an exception in the code at the time I did the division; when I tried to save this value in the database I got the error.
Hope this is useful to some of you reading the question - Thanks John for raising it.
Well, you already mentioned that you are trying to assign int to float. Try to convert that to float by multiply by 1.0.
float x = _randomLocation.Next(668); // note: the System.Random.Next method always returns an int
float y = 0 - image.Height; // note: image.Height is an int and is always around 300-600 in value in this application
I'm hitting a strange error when running a query in nhibernate using linq.
If I run the query in directly in mysql, everything works. If I rerun the linq query, I get no error, but only the id field (a string) is fetched. If I run the query many times, sometimes the first row is fetched correctly...
The only thing my google-fu found was this mysql bug, but I cannot see how they are related.
EDIT: It seems related to a varbinary(128) field I have in my database. If I remove this mapping, everything works again. I'm mapping this to a byte[] field in my class.
EDIT: I'm using NHibernate 2.1.2.4000 NHibernate.Linq 1.1.0.1001 (the newest GA versions), and I've tried with MySql Connector 6.1.2 and 6.2.4 (6.3.5 failed to install for some reason)
NHibernate.Util.ADOExceptionReporter [(null)] - System.IndexOutOfRangeException: Buffer index must be a valid index in buffer
at MySql.Data.MySqlClient.MySqlDataReader.GetBytes(Int32 i, Int64 fieldOffset, Byte[] buffer, Int32 bufferoffset, Int32 length)
at NHibernate.Driver.NHybridDataReader.GetBytes(Int32 i, Int64 fieldOffset, Byte[] buffer, Int32 bufferoffset, Int32 length)
at NHibernate.Type.AbstractBinaryType.Get(IDataReader rs, Int32 index)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
at NHibernate.Type.AbstractType.Hydrate(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
at NHibernate.Persister.Entity.AbstractEntityPersister.Hydrate(IDataReader rs, Object id, Object obj, ILoadable rootLoadable, String[][] suffixedPropertyColumns, Boolean allProperties, ISessionImplementor session)
at NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i, Object obj, String instanceClass, EntityKey key, String rowIdAlias, LockMode lockMode, ILoadable rootPersister, ISessionImplementor session)
at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, String rowIdAlias, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
Has anyone encountered this error before?
I found the error.
It's a NHibernate/MySql bug where it throws if the binary field is empty.
This is probably a shot in the dark but here goes nothing...
I have a Sitecore 6 site that I am developing locallty. When I pushed it to the production server, I now get an exception when trying to access the site. I had done an upgrade of the Sitecore version, and added the Forms module, among some other minor edits. So I moved everything to production, changed the connection strings, and changed the directory references in the web.config, but I still get this error.
My local machine still works fine, and even my staging server (hooked up via SVN and Cruise Control) works fine, but I can't fix this error on production.
At the bottom of the stack trace (below), it looks like it is trying to instantiate the search manager. Maybe that has something to do with it?
Or maybe I missed a setting when I moved everything? What settings need to be changed when the environment changes?
Here is what I've tried so far:
Re-copied all of the files and databases.
Gave full control permissions to the worker process, ASPNET, and Network Service users.
Double checked the directory paths in the web.config that needed to be configured.
Double checked the connection string in the connectionstring.config.
Recycled the App Pool
Stopped and started the site
Cleared my local browser cache (as they instruct you to do in the upgrade docs)
This is the exception that is being thrown when I try and access any page:
Thread information:
Thread ID: 1
Thread account name: 180716WEB1\testcom_web
Is impersonating: False
Stack trace: at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at Sitecore.Reflection.ReflectionUtil.SetProperty(Object obj, PropertyInfo property, Object value)
at Sitecore.Reflection.ReflectionUtil.SetProperty(Object obj, String name, Object value)
at Sitecore.Configuration.Factory.AssignProperties(Object obj, Object[] properties)
at Sitecore.Configuration.Factory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper)
at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
at Sitecore.Configuration.Factory.GetInnerObject(XmlNode paramNode, String[] parameters, Boolean assert)
at Sitecore.Configuration.Factory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper)
at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
at Sitecore.Configuration.Factory.GetInnerObject(XmlNode paramNode, String[] parameters, Boolean assert)
at Sitecore.Configuration.Factory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper)
at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert)
at Sitecore.Configuration.Factory.CreateObject(String configPath, String[] parameters, Boolean assert)
at Sitecore.Configuration.Factory.CreateObject(String configPath, Boolean assert)
at Sitecore.Search.SearchManager..cctor()
Custom event details:
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
It seems that there's something wrong with rights.
Make sure that you run the right identity(NETWORK SERVICES) in your AppPool and that you follow the Sitecore Installation instructions which can be found on SDN:
Kind regards,
Alex de Groot
Sitecore Solution Architect
It turned out to be that when I restored the database to production, it didn't re-associate the database user with it!!! Stupid me! For whatever reason, that causes this error to occur. I'm guessing that the SearchManager is setup as some sort of external service or something, to abstract things.
I got this error after moving a site between environments. The cause was the path for the sc.variable named dataFolder was incorrect. The value was a full file path and the site was in a different location on the new server.
<sc.variable name="dataFolder" value="c:\www\website\data\" />
Updating the web.config with the correct path fixed the problem.