Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Eskild 9 posts 79 karma points
    Oct 11, 2016 @ 14:20
    Eskild
    0

    Null Reference when submitting Umbraco Forms to custom data source

    I'm trying to make Umbraco Forms (Umbraco v7.5.3) save to my own data source. I followed this guide: http://www.nibble.be/?p=84

    And it appears to work-ish. I can connect and generate a form based on the table. Which is nice.

    My setup

    1. I add a new forms data source with the connection string:

      Provider=SQLNCLI11;Server=(localdb)\MSSQLLocalDB;Database=test;Integrated Security=SSPI;
      
    2. My table looks like this:

      table

      The Id (PK) property is configured as Identity

    3. I choose some fields I want to use in the form:

      field selection

    4. I choose which data types it should use:

      field types

      I'm a bit puzzled why the Id field is there. I didn't select it, and the guide I followed didn't have this field either :/?

    5. It generates this form for me:

      generated form

    Error

    But when I try to submit form data I get the following error. Which isn't nice.

    Server Error in '/' Application.

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
    Umbraco.Forms.Core.Providers.DatasourceTypes.MsSql.InsertRecord(Record record) +1750
    Umbraco.Forms.Web.Services.RecordService.storeRecord(Record record, Form form) +1574
    Umbraco.Forms.Web.Services.RecordService.Approve(Record record, Form form) +343 Umbraco.Forms.Web.Services.RecordService.Submit(Record record, Form form) +565
    Umbraco.Forms.Web.Controllers.UmbracoFormsController.SubmitForm(Form form, FormViewModel model, Dictionary2 state, ControllerContext context) +2245
    Umbraco.Forms.Web.Controllers.UmbracoFormsController.GoForward(Form form, FormViewModel model, Dictionary
    2 state) +205
    Umbraco.Forms.Web.Controllers.UmbracoFormsController.HandleForm(FormViewModel model, Boolean captchaIsValid) +785 lambdamethod(Closure , ControllerBase , Object[] ) +143
    System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +157
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
    2 parameters) +27
    System.Web.Mvc.Async.AsyncControllerActionInvoker.
    _5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
    System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29
    System.Web.Mvc.Async.WrappedAsyncResultBase
    1.End() +49
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9765121 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

    Questions

    • Why is the Id field added to my form when I didn't select it?
    • How is the form linked to my table? When I create a new form I cannot set a data source for it, and I cannot find any config on the generated form that points to my data source.
      • How are form fields linked to a table column? Is it via the "display name"?
    • Why do I get the above Null Reference when trying to submit my form?
  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Oct 13, 2016 @ 08:54
    Warren Buckley
    0

    Hello Eskild,
    Thanks for the detailed notes for this.

    I will need to spend some time trying to replicate the problem and get back to you.

    Can I ask a few more details please - what version of SQL is this?

    Thanks,
    Warren

  • Eskild 9 posts 79 karma points
    Oct 13, 2016 @ 09:58
    Eskild
    0

    Can I ask a few more details please - what version of SQL is this?

    It's running on the SQL server bundled with Visual Studio 2015 so that would be SQL Server v12.0.2000 (I think that is referred to as SQL Sever 2016 but not sure)

  • Comment author was deleted

    Oct 13, 2016 @ 09:29

    Think it might be due to the fact that the connstring isn't OleDB Compatible

  • Eskild 9 posts 79 karma points
    Oct 13, 2016 @ 10:06
    Eskild
    0

    What part isn't OleDB compatible?

     Provider=SQLNCLI11;Server=(localdb)\MSSQLLocalDB;Database=test;Integrated Security=SSPI;
    

    It connects to the database and can do schema lookups - so it's not totally broken :)

  • Comment author was deleted

    Oct 13, 2016 @ 09:31

    If you aren't scared to get your hands dirty with some code, I just released a couple of addons form forms that allow you to connect third party db data and submit to those, via workflow or via datasource (but you'll have to map your db table to a poco) http://www.nibble.be/?p=505

  • Eskild 9 posts 79 karma points
    Oct 13, 2016 @ 10:01
    Eskild
    0

    This seems like the exact thing I'm looking for :) I'll give it a try

  • Eskild 9 posts 79 karma points
    Oct 13, 2016 @ 11:13
    Eskild
    0

    Hmmm, after installing "UI-O-MATIC LOVES UMBRACO FORMS" umbraco have become extremely slow.

  • Eskild 9 posts 79 karma points
    Oct 13, 2016 @ 12:16
    Eskild
    0

    Sadly I cannot use the addon as the data source needs to be maintained without having to code, so having to create a POCO is a deal breaker :(

  • Comment author was deleted

    Oct 13, 2016 @ 12:18

    Ok understand that :) Then I think it's time for @Warren to do some debugging

  • Comment author was deleted

    Oct 13, 2016 @ 11:14

    the backoffice or the frontend?

  • Eskild 9 posts 79 karma points
    Oct 13, 2016 @ 11:18
    Eskild
    0

    Installing Umbraco Forms via the Umbraco Frontend also, not just via Nuget fixed it.

  • Comment author was deleted

    Oct 13, 2016 @ 11:19

    strange but glad it's fixed

  • Eskild 9 posts 79 karma points
    Oct 13, 2016 @ 12:37
    Eskild
    0

    So I've been poking around a bit and found these

    UmbracoForms\Data\datasources\3b43cee4-e31b-4ac2-aba7-9cc022a35fe6.json
    UmbracoForms\Data\forms\ab45333b-1cf1-4526-b2c8-474dae089608.json
    

    The latter holdes info about which fields the form have and how they map to the data source. Great! But changing the json file does nothing :(

    So my question is. How do I make Umbraco aware of my changes in the json file, or where do I edit the source the json file is generated from?

  • Eskild 9 posts 79 karma points
    Oct 13, 2016 @ 13:01
    Eskild
    0

    I'm not sure what I did. But now Umbraco Forms caught up with some of my changes. And I think I figured out what the problem is.

    First off, the Id column is set to IDENTITY so the default form that is generated includes the Id. This is a problem. So I removed it from the form but the datasource.mappings section still has a reference to the Id column and that was causing issues. So in my desperation I added the Id field to the form again, via the frontend, but this new Id field didn't have a link to data source column. In other words the dataSourceFieldKey was null. And that was causing the null reference in the OP.

    So in conclusion the data source aspect of Umbraco Forms needs a bit of work. Perhaps it's already on your roadmap?

    I'm still interested in knowing why changing the json file only sometimes updates the frontend.

    Almost forgot :) The fix was to remove the field containing the Id in pages.fieldSets.containers.fields and the map containing the Id column in datasource.mappings inside the UmbracoForms\Data\forms\ab45333b-1cf1-4526-b2c8-474dae089608.json file. And then

    1. save the file
    2. close Visual Studio
    3. open it again
    4. relaunch the site
    5. open the umbraco forms admin section and reload a few times
    6. goto step 2 if it didn't work
  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Oct 13, 2016 @ 14:33
    Warren Buckley
    0

    Hello Eskild,
    Great to see you being active in finding a solution.

    These JSON files are not intended to be edited manually. These files are cached as .NET objects for use and hence you are seeing a delay. Restarting the site/app pool will obviously clear the cache here for this.

    Yes it does seem that you have found a bug and I recommend posting details of this on the issue tracker so it can be put into the backlog and considered for next sprint grooming meeting.

    http://issues.umbraco.org/issues/CON

    Many Thanks.
    Warren

Please Sign in or register to post replies

Write your reply to:

Draft