Developer forum

Forum » Development » user.save() throws date error

user.save() throws date error

Steen Nørgaard Perdersen
Reply

Hi All,

 

I have this code to make a new user from an import. It worked fine on a previous version (8.2something)


In 8.3.0.5 I get

        SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

on user.save();

 

Am I missing something? Values in comments are from log, just before save...

 

(user is Dynamicweb.Modules.UserManagement.User):

 

   var user = new User();
                            user.Password = autoGenerated(); // zZN6hh1r
                            user.UserName = ADentry.username; // mej
                            user.ValidFrom = DateTime.Now; // 20-12-2013 13:51:00
                            user.ValidTo = DateTime.Now.AddYears(50); // 20-12-2063 13:51:00
                            user.Name = ADentry.fullname; // Morten Erik Jensen
                            if (!String.IsNullOrEmpty(ADentry.email))
                            {
                                user.Email = ADentry.email;
                            }
                            {
                                user.Email = ADentry.username + "@" + adDomain; // mej@bleau.lan
                            }
                            user.Save();

Replies

 
Steen Nørgaard Perdersen
Reply

Nevermind.... bug related to 8.3.0.5, works on later version

 

//steen

 
Morten Bengtson
Reply
This post has been marked as an answer

Whenever you get an error like this, it is usually because a DateTime property has not been set properly before you save.

 

 

In this case the problem is the PasswordDate property on the user.

In DW 8.3.0.5 the PasswordDate was initially set to new DateTime(), which is the same as 01/01/0001, but this is not within the accepted datetime range in SQL Server, which is between 01/01/1753 to 12/31/9999.

 

 

This was changed in a later release so that PasswordDate is set to DateTime.Now when you instantiate a new User.

 

 

So you just need to make sure that you set all DateTime properties to a date that is within the range accepted by SQL Server.

Votes for this answer: 1

 

You must be logged in to post in the forum