Sql Compact decimal precision error

人走茶凉 提交于 2019-12-13 01:15:27

问题


I have a Windows Phone app using Linq to Sql with Sql Compact. My Item table has a wide variety of field types, including some decimal and nullable decimal values.

When testing in the emulator, at startup and reading the Item table in a background thread to populate into a ListBox on the main page, I'll get an unhandled ArgumentException:

Precision value '29' is either less than 0 or greater than the maximum allowed precision of 38.

This is intermittent, perhaps once out of every 15 to 20 times I debug the project, but it's always '29'. I haven't gotten this error on a physical device, but I haven't done as much testing there yet.

Why is this happening? I've tried searching the web, but every instance I see of this error, the precision value is indeed greater than 38. I supposed I could wrap this in a try-catch block, but that doesn't really fix the problem, whatever it is. While this has happened when the database has data, it also happens with a new, empty database. The actual decimal values when data exists are very low (some are currencies, some are weights and dimensions).

Debugging usually works fine if I continue from the error.

Stack trace:

at System.Data.SqlServerCe.SqlMetaData.Construct(String name, SqlDbType dbType, Byte precision, Byte scale)
at System.Data.SqlServerCe.SqlMetaData..ctor(String name, SqlDbType dbType, Int64 maxLength, Byte precision, Byte scale, Int64 localeId, SqlCompareOptions compareOptions, Type userDefinedType)
at System.Data.SqlServerCe.MetaData..ctor(String name, SqlCeType typeMap, Byte precision, Byte scale, Int64 maxLength, String databaseName, String schemaName)
at System.Data.SqlServerCe.SqlCeDataReader.PopulateMetaData(Int32 columnCount, IntPtr prgColumnInfo)
at System.Data.SqlServerCe.SqlCeDataReader.FillMetaData(IntPtr pIUnknown)
at System.Data.SqlServerCe.SqlCeDataReader.FillMetaData(SqlCeCommand command)
at System.Data.SqlServerCe.SqlCeCommand.InitializeDataReader(SqlCeDataReader reader, Int32 resultType)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteDbDataReader(CommandBehavior behavior)
at Microsoft.Phone.Data.Common.DbCommand.ExecuteReader()
at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult, Boolean isCompiledQuery)
at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries, Boolean isCompiledQuery)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Linq.Enumerable.<TakeIterator>d__40`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Data.Item.List()
at Pages.Main.Thread_DoWork(Object sender, DoWorkEventArgs e)
at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
at System.ComponentModel.BackgroundWorker.OnRun(Object argument)
at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadPool.WorkItem.doWork(Object o)
at System.Threading.Timer.ring()

来源:https://stackoverflow.com/questions/14115354/sql-compact-decimal-precision-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!