Site Search:
Sign in | Join | Help

eConnect 10 Hello World Project

Last post 02-26-2009 3:18 PM by Steve Gray. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 01-16-2008 11:37 AM

    • Steve Gray
    • Top 10 Contributor
      Male
    • Joined on 01-10-2007
    • Bradenton, Florida
    • Guru
    • Points 2,318

    eConnect 10 Hello World Project

    I get asked frequently 'how do I get started', and I usually say 'read the manual', but I'll give this a shot.

    Here's a short walk through of how to get started using eConnect

    First of all, understand that there are two ways to code eConnect. You can just use what I call the 'direct' method, or you can 'serialize'. I'm not going to get into serialization here, because it's a lot more complicated, but it involves instantiating eConnect objects, then populating them, then sending the object itself to eConnect. The advantage to using serialization is that eConnect does some checking and validation for you along the way and will solve some issues earlier. It will also prepopulate a lot of default values.

    Lately I've been using the 'direct' method, because it's simpler and I can code it quicker. So, here goes.

    Install eConnect according to the install guide. You'll only need the 'incoming service', I don't have a lot of use for the 'outgoing service' (but I'd be happy to post contrary opinions). Also, download the help file, I use this all day long and I reference it below.

    Create a project for eConnect. For this example, we're going to discuss a standard windows app, but in practice I usually use a Windows Service app or a Web Service.

    Bring the eConnect, Serialization, and MiscRoutines dlls into your app and set references to them. These are installed on your PC in the C:\Program Files\Common Files\microsoft shared\eConnect 10\Objects\Dot Net folder.

    Add this code to your app

    Imports System
    Imports System.Xml
    Imports System.Xml.Serialization
    Imports System.IO
    Imports Microsoft.GreatPlains.eConnect
    Imports Microsoft.GreatPlains.eConnect.Serialization
    Imports Microsoft.GreatPlains.eConnect.MiscRoutines
    
    
    
        '==========================================================================
        'this code will accept any econnect doc
        '==========================================================================
        Public Shared Sub main(ByVal xDoc As XmlDocument, ByVal db As String)
            Dim strServer As String = System.Configuration.ConfigurationManager.AppSettings("server")
    
    
            Dim strConnect As String = "data source=" & strServer & "; initial catalog=" & db & "; integrated security=SSPI; persist security info=False; packet size=4096"
            Dim eConnResult As Boolean
    
    
            'Instantiate an eConnectMethods object
            Dim eConnObject As New eConnectMethods
    
    
            Try
    
    
                'If the update returned TRUE, it was successfully completed
                eConnResult = eConnObject.eConnect_EntryPoint(strConnect, EnumTypes.ConnectionStringType.SqlClient, xDoc.OuterXml, EnumTypes.SchemaValidationType.None)
            Catch ex As eConnectException
                Throw New Exception(ex.Message)
            Catch ex As System.Data.SqlClient.SqlException
                Dim myError As System.Data.SqlClient.SqlError
                Dim strMsg As String = ""
                For Each myError In ex.Errors
                    strMsg += myError.Message + vbCrLf
                Next
                Throw New Exception(strMsg)
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Sub

    I'm not going to explain most of the code above, that's out of the scope of this article. However, note that we pass in an XML document. That document is an XML eConnect doc. I have several examples here (scroll to the bottom), and the help file has a lot, also.  

     I know that the error handling looks kind of 'over the top', but trust me, you need it.

    If anyone has a specific question about the code, send it and I'll document it here.

    <a xmlns:xsi="<a href=" href="http://www.w3.org/2001/XMLSchema-instance%22%3Ehttp://www.w3.org/2001/XMLSchema-instance%3C/a">http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a</a>" xmlns:xsd="<a href="<a href="http://www.w3.org/2001/XMLSchema%22%3Ehttp://www.w3.org/2001/XMLSchema%3C/a">http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a</a>">
    
    
    <RMCustomerMasterType>
     <taUpdateCreateCustomerRcd>
      <CUSTNMBR>MYCUSTNUMBER</CUSTNMBR><!-- (REQUIRED) string(15) Customer number-->
      <CUSTNAME>MYCUSTNAME</CUSTNAME>
     </taUpdateCreateCustomerRcd>
    </RMCustomerMasterType>
    </eConnect>

     

    Load the doc above into an XML document, and submit it to the 'main' sub. You'll have errors, I always do. Search this forum for the errors, you should find all of them.

    The above is 1.0 documentation. Please send feedback on how I can improve it.

    Steve Gray, MCDBA
    Technical Editor
    steve@VSToolsForum.com
    • Post Points: 0
  • 03-05-2008 10:04 AM In reply to

    Re: eConnect 10 Hello World Project

    Hi,
    In our office environment, we installed the GP database server in another server (Ex: ServerName: PCNUM1\SQL2005). And they installed Econnect in my Desktop. I am able to connect to that SQL server using SQL server credentials (In econnect 10--> Requester setup & Microsoft Sql server management studio express). But I am not able to connect using "Windows Authentication".

     

    In this scenario, How can i use the EConnect to get/insert value into GP server.?  Because, I am getting "Login failed for user ''. The user is not associated with a trusted SQL Server connection." error, while running the source code.

     

    for more info, please see my code below:

    Dim strConnect As String = "data source=PCNUM1\SQL2005; initial catalog=TWO; integrated security=SSPI; persist security info=False; packet size=4096"

    Dim eConnResult As Boolean

     

    'Instantiate an eConnectMethods object

    Dim eConnObject As New eConnectMethods Dim xDoc As New XmlDocument

    Dim xmlStr As String

    xmlStr = "<eConnect>"

    xmlStr = xmlStr & "<RMCustomerMasterType>"

    xmlStr = xmlStr & "<taUpdateCreateCustomerRcd>"

    xmlStr = xmlStr & "<CUSTNMBR>MYCUSTNUMBER</CUSTNMBR><!-- (REQUIRED) string(15) Customer number-->"

    xmlStr = xmlStr & "<CUSTNAME>MYCUSTNAME</CUSTNAME>"

    xmlStr = xmlStr & "</taUpdateCreateCustomerRcd>"

    xmlStr = xmlStr & "</RMCustomerMasterType>"

    xmlStr = xmlStr & "</eConnect>"

    xDoc.LoadXml(xmlStr)

    Try

     

    'If the update returned TRUE, it was successfully completed

    eConnResult = eConnObject.eConnect_EntryPoint(strConnect, EnumTypes.ConnectionStringType.SqlClient, xDoc.OuterXml, EnumTypes.SchemaValidationType.None)

    Catch ex As eConnectException

    Throw New Exception(ex.Message)

    Catch ex As System.Data.SqlClient.SqlException Dim myError As System.Data.SqlClient.SqlError

    Dim strMsg As String = ""

    For Each myError In ex.Errors

    strMsg += myError.Message + vbCrLf

    Next

    Throw New Exception(strMsg)

    Catch ex As Exception

    Throw New Exception(ex.Message)

    End Try

    • Post Points: 0
  • 04-15-2008 6:22 PM In reply to

    Re: eConnect 10 Hello World Project

    >>In this scenario, How can i use the EConnect to get/insert value into GP server.?
    >>Because, I am getting "Login failed for user ''. The user is not associated with a
    >>trusted SQL Server connection." error, while running the source code.

    There are several aspects to eConnect architecture and security that you need to understand to troubleshoot problems like this.

    First of all, eConnect is made up of

    1. stored procedures in the Great Plains company database (AKA "business objects")
    2. DTC / COM+ objects
    3. .NET assemblies.
      and, in some environments:
    4. MSMQ is involved as well--though that does not apply in your example.

    eConnect assumes / requires integrated security be used.  That means that:

    1. the machine you are running the eConnect application on must be a member of the same domain as the Great Plains SQL server
    2. the user account you are logged in with must be a domain user account of that same domain
    3. this NT domain account must be set up as a SQL login
    4. the SQL login must have an associated SQL user in the Great Plains company database
    5. the SQL login must have an associated SQL user in the Great Plains Dynamics database
    6. the two SQL database users above must both be members of the DYNGRP database role
    7. DTC security must be set up appropriately
    8. the COM+ package account must be set to use this same NT user account

    I can provide more details on any of the above if you like.

    Of course eConnect must be installed on both the Great Plains SQL server, and the eConnect .NET runtime must be installed on any machine that will be running an eConnect application.

    I have also put together a detailed Word document with specific eConnect DTC troubleshooting steps.  If you hare interested in this, just let me know.

    Sincerely,

    David Rueter
    drueter@assyst.com

    • Post Points: 0
  • 04-16-2008 8:30 AM In reply to

    • Steve Gray
    • Top 10 Contributor
      Male
    • Joined on 01-10-2007
    • Bradenton, Florida
    • Guru
    • Points 2,318

    Re: eConnect 10 Hello World Project

    Dave:

    Would you consider creating a new thread and posing your doc, and then linking to that thread from this one? I'm sure the community would appreciate it! I've also got some DCOM help posted here http://vstoolsforum.com/forums/p/170/366.aspx#366 <starts twitching violently>

     

    Steve Gray, MCDBA
    Technical Editor
    steve@VSToolsForum.com
    • Post Points: 0
  • 04-17-2008 3:50 AM In reply to

    Re: eConnect 10 Hello World Project

    Sure.. Please .... :)

    • Post Points: 0
  • 02-26-2009 2:13 PM In reply to

    Re: eConnect 10 Hello World Project

    David, thanks for the great info here. I'm runing into a little bit of issue with eConnect 10. I installed it on the my workstation and on the server. They're both on the same domain. I use my workstation to run the sample program I get login error. I ran the same program on the server yesterday, there was problem. Today I ran it again on the server this time I received error on eConnectMethods. The error said

     

    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.

    ************** Exception Text **************
    System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
       at System.EnterpriseServices.Thunk.Proxy.CoCreateObject(Type serverType, Boolean bQuerySCInfo, Boolean& bIsAnotherProcess, String& uri)
       at System.EnterpriseServices.ServicedComponentProxyAttribute.CreateInstance(Type serverType)
       at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(Type serverType, Object[] props, Boolean bNewObj)
       at eConnectGP.Form1.Button3_Click(Object sender, EventArgs e)
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


    ************** Loaded Assemblies **************
    mscorlib
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    ----------------------------------------
    eConnectGP
        Assembly Version: 1.0.0.0
        Win32 Version: 1.0.0.0
        CodeBase: file:///T:/eConnectGP.exe
    ----------------------------------------
    Microsoft.VisualBasic
        Assembly Version: 8.0.0.0
        Win32 Version: 8.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
    ----------------------------------------
    System
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Windows.Forms
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System.Drawing
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    System.Runtime.Remoting
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
    ----------------------------------------
    Microsoft.Dynamics.GP.eConnect
        Assembly Version: 10.0.0.0
        Win32 Version: 10.00.1072.000
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.Dynamics.GP.eConnect/10.0.0.0__31bf3856ad364e35/Microsoft.Dynamics.GP.eConnect.dll
    ----------------------------------------
    System.Xml
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
    ----------------------------------------
    System.EnterpriseServices
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/Windows/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
    ----------------------------------------

    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.

    For example:

    <configuration>
        <system.windows.forms jitDebugging="true" />
    </configuration>

    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.


    any input is appreciated.

     

    Thanks

    Cory

    • Post Points: 0
  • 02-26-2009 3:18 PM In reply to

    • Steve Gray
    • Top 10 Contributor
      Male
    • Joined on 01-10-2007
    • Bradenton, Florida
    • Guru
    • Points 2,318

    Re: eConnect 10 Hello World Project

    If I understand correctly, you have and application on your workstation and the Dynamics SQL server is someplace else on the domain. To fix this issue, you'll have to get the docs out (there is a programmer's guide PDF file) and find the section on DCOM. Carefully follow the instructions.

    Personally, I don't do this. I've spent too much time getting DCOM working on client computers. Sometimes it takes days. And, if your application is going to run on multiple PCs, you have to do this on every PC.

    I always create a very simple web service (it's posted on this blog someplace) on the SQL Server and I have my client connect to that, instead of sending a transaction across DCOM. Saves lots of pain. There is no security or configuration for a web service, (by default), you're just sending SOAP XML packets across the intranet.

    Steve Gray, MCDBA
    Technical Editor
    steve@VSToolsForum.com
    • Post Points: 0
Page 1 of 1 (7 items)