This is a migrated thread and some comments may be shown as answers.

Default DateTime column with GETDATE()

1 Answer 95 Views
Databases and Data Types
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
BekirSami
Top achievements
Rank 1
BekirSami asked on 23 Dec 2010, 03:45 PM
Hi,
I have a notnull DateTime column named InsertedDate and its Default Value is GETDATE() for getting server time for inserting new values automatically. At Code behind I do not assign this column.

In model scheme explorer I select "backend calculated". But  gives error when inserting to db.
Is there any way to succeed this.

Insert of '2127628280-' failed: Telerik.OpenAccess.RT.sql.SQLException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.
   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()
   at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()
   at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)
INSERT INTO [UserPasswordHistory] ([InsertedBy], [InsertedDate], [OldPassword], [UserId]) VALUES (?, ?, ?, ?)
select scope_identity()
(set event logging to all to see parameter values) Telerik.OpenAccess.RT.sql.SQLException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.
   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()
   at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()
   at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 27 Dec 2010, 09:58 AM
Hello Hasan,

The IsBackendCalculated option is actually used for autoinc primary key columns. In case of a column that is not a primary key but is still populated by the server, you will have to use another option that is set on the class' property and not on the column itself. Just open the diagram, select the InsertedDate property and change the Kind option to PersistentReadOnly. This way OpenAccess will not try to persist the value of this property but you will still be able to read it. Hope that helps.

All the best,
Alexander
the Telerik team
Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Tags
Databases and Data Types
Asked by
BekirSami
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or