InfoPath 2013 Oracle database queries - InfoPath Dev
in

InfoPath Dev

InfoPath 2013 Oracle database queries

Last post 10-16-2015 07:20 AM by dcg38524. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 10-14-2015 04:39 AM

    InfoPath 2013 Oracle database queries

     Hello Everyone,

    I am new member to this forum and also very new in creating InfoPath forms.  Recently I created a simple infopath 2013 form using Visual Studio 2012 C# to query a oracle database, the C# code builds ok but crashes when invoked.

    The code was fully tested and worked using only Visual Studio C# Web project before rolling out to InfoPath 2013.  I am confused and just not sure what's wrong or what next steps should be, maybe one of the forum members have experienced the same problem and can help me with this dilemma.


    Any help would be greatly appreciated,

    Kind regards,

    Don 


     

    using Microsoft.Office.InfoPath;
    using System;
    using System.Xml;
    using System.Xml.XPath;
    using System.Data;
    using System.Windows.Forms;
    using Oracle.ManagedDataAccess.Client; // ODP.NET Oracle managed provider
    using Oracle.ManagedDataAccess.Types;


    namespace WebTestTool2
    {
        public partial class FormCode
        {

            public void InternalStartup()
            {
                ((ButtonEvent)EventManager.ControlEvents["CTRL4_5"]).Clicked += new ClickedEventHandler(CTRL4_5_Clicked);
                EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
            }

            public void CTRL4_5_Clicked(object sender, ClickedEventArgs e)
            {
              

                MessageBox.Show("Hello World !!!");
            }

            public void FormEvents_Loading(object sender, LoadingEventArgs e)
            {
                string oradb = "Data Source=xxx;User Id=xxx;Password=xxx;";
                OracleConnection conn = new OracleConnection(oradb);  // C#
                conn.Open();

                //scripts to get value of Infopath field
                XPathNavigator Period1 = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:RTPA", this.NamespaceManager);


                OracleParameter parm = new OracleParameter();
                parm.OracleDbType = OracleDbType.Decimal;
                parm.Value = Period1.Value;

                OracleCommand cmd = new OracleCommand();
                cmd.Connection = conn;
                // cmd.Parameters.Add(parm);
                cmd.Parameters.Add("@Search", OracleDbType.NVarchar2).Value = Period1.Value;
                cmd.CommandText = "select UPPER(CHAMELEON_COMPONENT) from TEF_Module where TICKET_ID_ = :1";
                cmd.CommandType = CommandType.Text;
                OracleDataReader dr = cmd.ExecuteReader();

                //scripts to set value of Infopath field       
                XPathNavigator P2 = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:Component", this.NamespaceManager);

                dr.Read();
                P2.SetValue(dr.GetString(0));

                conn.Dispose();


                XPathNavigator dataSource;
                dataSource = this.MainDataSource.CreateNavigator();
                dataSource.SelectSingleNode(
                    "/my:myFields/my:Author", NamespaceManager).SetValue(this.User.UserName);

     
            }
        }
    }
     

  • 10-14-2015 10:49 AM In reply to

    Re: InfoPath 2013 Oracle database queries

    So, when you run in debug, where does the code fail? Or does it only fail in the browser? Anything in the log files on the SharePoint server? Are the Oracle components installed on the SharePoint server?
    Hilary Stoupa

  • 10-15-2015 05:16 AM In reply to

    Re: InfoPath 2013 Oracle database queries

     Hi Hilary,

    When applying the Oracle connection code to the"public void CTRL4_5_Clicked(object sender, ClickedEventArgs e)"

    1.  The code builds fine via. Visual Studio 2012 no debug errors and InfoPath 2013 filter appears
    2. Adding data to RTPA textbox no errors.
    3. when I hit the button within the form the Error Message below appears.
    NOTE: I have not installed Oracle components on the SharePoint 2013 server.

     

    Error Message:

    An unhandled exception has occurred in the form's code

    System.Threading.ThreadAbortException
    Thread was being aborted.
       at WebTestTool2.FormCode.CTRL4_5_Clicked(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
     

  • 10-15-2015 07:38 AM In reply to

    Re: InfoPath 2013 Oracle database queries

    So, when you run the form in debug / preview, the form works as anticipated? The error is when the form is opened the browser?
    Hilary Stoupa

  • 10-15-2015 08:26 AM In reply to

    Re: InfoPath 2013 Oracle database queries

     Hi Hilary,

     

    1. When I select the Visual Studio 2012 debugger there are no errors
    2. Then the InfoPath 2013 browser filler form appears ok
    3. Then I added some data into the textbox to be queried by the Oracle database no errors
    4. Then when I push the button to perform what I think is the Oracle query I do get the error box(see errors below)

     I am a little confused and being so new to InfoPath form it could be my syntax in assigning textboxes and buttons,  the Oracle connect C# code works fine using VS 2012 Web browser (see VS 2012 working code below)

     

    InfoPath 2013 Error

    An unhandled exception has occurred in the form's code

     

    System.Threading.ThreadAbortException
    Thread was being aborted.
       at WebTestTool2.FormCode.CTRL4_5_Clicked(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
     

     

     Visual Studio 2012 C# Web working code:

     using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Oracle.ManagedDataAccess.Client; // ODP.NET Oracle managed provider
    using Oracle.ManagedDataAccess.Types;

    namespace OraWinApp
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                string oradb = "Data Source=xxx;User Id=xxx;Password=xxx;";
                OracleConnection conn = new OracleConnection(oradb);  // C#
                conn.Open();

                OracleParameter parm = new OracleParameter();
                parm.OracleDbType = OracleDbType.Decimal;
                parm.Value = Component.Text;

                OracleCommand cmd = new OracleCommand();
                cmd.Connection = conn;
                // cmd.Parameters.Add(parm);
                cmd.Parameters.Add("@Search", OracleDbType.NVarchar2).Value = Component.Text;
                cmd.CommandText = "select UPPER(CHAMELEON_COMPONENT) from TEF_Module where TICKET_ID_ = :1";
                cmd.CommandType = CommandType.Text;
                OracleDataReader dr = cmd.ExecuteReader();
                dr.Read();
                label1.Text = dr.GetString(0);
                conn.Dispose();

            }
        }
    }

  • 10-15-2015 11:22 AM In reply to

    Re: InfoPath 2013 Oracle database queries

    I'm confused by your initial code sample where it appears you are running the code on form load. Your button click appears to only show a message box - which if this is browser form will fail - but it looks like it is filler form from the using statements. Or did you change this code from your initial post? At any rate, I'd add some breakpoints and run in debug.
    Hilary Stoupa

  • 10-15-2015 01:38 PM In reply to

    Re: InfoPath 2013 Oracle database queries

     Hilary,

     You are 100% correct, I've tried to run the Oracle connection query using button & form load as you suspected both failed . 

     

    It appears the code breaks on the line below:

    OracleConnection conn = new OracleConnection(oradb);  // C#
    conn.Open();

  • 10-15-2015 02:15 PM In reply to

    Re: InfoPath 2013 Oracle database queries

    Hmmm. I'm really not sure what to suggest. conn.Open() is what gives you the thread is being aborted error?
    Hilary Stoupa

  • 10-16-2015 07:20 AM In reply to

    Re: InfoPath 2013 Oracle database queries

    Hilary,

    Adding "OracleConnection conn = new OracleConnection(oradb);" to the button click selection and once I select the button within the filler form it gives me aborted error.

    Adding "OracleConnection conn = new OracleConnection(oradb);" to the filler section gives me the thread via. aborted error.

     

            public void CTRL4_5_Clicked(object sender, ClickedEventArgs e)
            {

                OracleConnection conn = new OracleConnection(oradb);  // C#
                // conn.Open();

                //scripts to get value of Infopath field
                XPathNavigator Period1 = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:RTPA", this.NamespaceManager);
                String P1 = Period1.Value;

                //scripts to set value of Infopath field       
                XPathNavigator P2 = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:Component", this.NamespaceManager);
                P2.SetValue(P1);

Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.