This tutorial describes how to connect to Magento.
In this walkthrough:
In order to connect to Magento you need to have the corresponding account, dotConnect for Magento installed and IDE running. You also have to know the required connection parameters described below.
Note that if you do not use design-time (specifically, if you do not place designer MagentoConnection component from the Toolbox to the form), you have to embed licensing information manually. This is described in topic Licensing.
To establish a connection to server you have to provide the required connection parameters to dotConnect for Magento. This information is used by MagentoConnection component to connect to Magento. The parameters are represented as a connection string. You can compose the connection string manually or have dotConnect for Magento construct it for you.
The following connection string parameters are required:
dotConnect for Magento allows connecting to both Magento 1.x and Magento 2.x version. For connecting to Magento 1.x, you need to specify the API Key parameter. You can find the API Key in the User information section of your Magento dashboard.
For connecting to Magento 2.x, you need to set the Service Version parameter to Ver2 and specify the Password parameter instead of API Key
Design time creation
The following assumes that you have IDE running, and you are currently focused on a form designer.
Run time creation
You can also configure a connection at run-time by setting its ConnectionString property (note that you have to add references to Devart.Data.Magento.dll, Devart.Data.SqlShim.dll, and Devart.Data.dll assemblies):
Using connection string builder
If you decide to setup connection by assigning values to several properties, consider using MagentoConnectionStringBuilder class. It has all of the possible connection settings exposed as properties, thus allowing to customize the connection at full extent.
Notice that in this example we used MagentoConnection constructor that accepts connection string as argument.
For the information on arguments allowed in the connection string, refer to the description of the MagentoConnection.ConnectionString property.
Creating Connection in Server Explorer
To create a Server Explorer connection, you just need to:
After this you can browse Magento objects in Server Explorer.
Opening a connection is as simple as that:
Of course, the myConnection1 object must have a valid connection string assigned earlier. When you call Open, dotConnect for Magento tries to find the host and connect to Magento. If any problem occurs it raises an exception with brief explanation on what is wrong. If no problem is encountered dotConnect for Magento tries to establish the connection during ConnectionTimeout interval. Finally, when connection is established, the Open method returns and State property is changed to Open.
In design time you can connect to server in few steps:
Or you can simply change the State property to Open in the Properties window to establish a connection using the current connection string.
To close a connection call its Close method, or set its State property to Closed.
The following example summarizes aforementioned information and shows how to create, setup, open, use and then close the connection.
The sample code connects to server, shows its version and then closes the connection. This actually is a rare usage, because in real applications connections are used by other objects like MagentoCommand, MagentoDataReader and others. For more information on this please see corresponding tutorials or reference information.
You can modify connection by changing properties of MagentoConnection object. Keep in mind that while some of the properties can be altered freely, most of them close connection when new value is assigned.