GPConnection object

The GPConnection object is used in scripts instead of the RetreiveGlobals dynamic link library that was used in Microsoft Dynamics GP 9.0 and previous versions.

Open method

The Open method allows you to open an ADO connection using the current GP user login information.This method uses the data source that is in use when Microsoft Dynamics GP is open. If you want to use a default company database (TWO or GPDAT) for this method, then you must set the Open value in the connection string before using the Open method. You will not be able to update the connection string after the Open method is called. There is no close method for this object. Once the connection is returned to the same way the connection object was initially created in the script, that connection object can be closed normally.


All properties for the Open method will return string values.

The following example is the Open script. It opens the data connection.

set MyCon = CreateObject("ADODB.Connection")
MyCon.Connectionstring = "database=GPDAT"

The following is an example of creating the ADO record set.

set recset = CreateObject("ADODB.Recordset")

The following is an example of creating the ADO connection.

set MyCon = CreateObject("ADODB.Connection")

The following is an example of executing the update command

recset = MyCon.Execute(updatecommand )

The following is an example of closing the ADO Connection.


The following are examples of retrieving the properties exposed by the new GPConnection object.

MsgBox GPConnection.GPConnUserDate
MsgBox GPConnection.GPConnInterCompanyID
MsgBox GPConnection.GPConnUserID
MsgBox GPConnection.GPConnUserName
MsgBox GPConnection.GPConnDataSource

UserDate property

The UserDate property contains the current user date.


CompanyID property

The CompanyID property contains the intercompany ID (company database ID).


The following is an example of initializing the connection string to specify a default database. In this case it is set to the current company. This could be set to a constant database, such as GPDAT.

MyCon.Connectionstring = "database=" + GPConnection.GPConnInterCompanyID

UserID property

The UserID property contains the current User ID.


UserName property

The UserName property contains the name of the current user.


The following is an example of creating a string to update the customer name in the customer master table.

updatecommand = "update RM00101 set [CUSTNAME]='IM Customer' where 

DataSource property

The DataSource property contains the name of the current data source that is being used in Microsoft Dynamics GP.



Documentation Feedback