Site Search:
Sign in | Join | Help

eConnect 10 Hello World Project

Last post 04-17-2008 3:50 AM by sensoft2000. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 01-16-2008 11:37 AM

    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
    • 71.100.137.9
  • 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

    • 202.54.171.195
  • 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

    • 69.230.202.178
  • 04-16-2008 8:30 AM In reply to

    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
    • 71.100.135.32
  • 04-17-2008 3:50 AM In reply to

    Re: eConnect 10 Hello World Project

    Sure.. Please .... :)

    • 125.17.132.2
Page 1 of 1 (5 items)