Monday, December 10, 2007

The field is too small to accept the amount of data you attempted to add

Like the other developers, the error code print out would make easier to find out the way where we must to debug and fix the problem.

Like the error code below
System.Data.OleDb.OleDbException: The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at Register.ExecuteCommand(String MyCmd) in d:\Project\fake\UserManagement\Register.aspx.cs:line 60
The error code above represent that our Table Field Size didn't have sufficient Field Size to handle the data longer than the available Field Size.

On Ms. Access database the default length for Text Data Type is 50. The maximum length of a Text Data Type is 255. So, please provide the sufficient Field Size for the data you want to be saved on an Access database.



If the data is longer than 255 it might you need consider to use a Memo field, then you can get a whole lot more characters, but this may be overkill.

Operation must use an updateable query

It might be sometime you will got this error when working with ASP.NET and Ms. Access database.
System.Data.OleDb.OleDbException: Operation must use an updateable query. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at Register.ExecuteCommand(String MyCmd) in d:\Project\fake\UserManagement\Register.aspx.cs:line 60
The error would be different depending on your ASP.NET code. But the main error will looks similar.
This is very well known problem and may occur under the following circumstances
  • An ASP.NET worker process (Aspnet_wp.exe) runs under the default ASPNET account.
  • You do not enable impersonation on that application.
  • You try to connect to or write to an Access database.
To solve the problem you need to give the permission to ASPNET account. The exact permissions are Modify. Although on Windows Server 2003, it is probably the NETWORK SERVICE account.
  1. Right click on the folder containing the Access database, then choose Properties | Security.
  2. Click "Add".
  3. Click "Advanced" and make sure the "From this location..." entry matches the current box.
  4. Click "Find Now" and you will be presented with a list of user accounts.
  5. Double click the NETWORK SERVICE entry, then click OK.
  6. Select the "Modify" option, then click "Apply".
The image shown below illustrated the process.




Hope this helps.

Reference :
(1) http://support.microsoft.com/default.aspx?scid=kb;en-us;316675