[]
        
(Showing Draft Content)

Creating Connection

To establish a connection to a Magento data source, the ADO.NET Provider can be used through the C1MagentoConnection class. This class requires a connection string to be provided as an argument, which can be created in either of the following ways:

  • Generated using the C1MagentoConnectionStringBuilder class by specifying individual statements.
  • Constructed manually by writing the connection string directly.

The ADO.NET provider for Magento allows you to use either the Basic Authentication or the OAuth based authentication.

Basic Authentication

To use Basic authentication, the connection string should include the TokenType property. There are two ways to specify the TokenType:

  • Admin - token service is provided for administrators and returns a unique access token in exchange for the username and password for a Magento account. E.g. Type='admin'.
  • Customer - token service is provided for customers and returns a unique access token in exchange for the username and password for a Magento account. E.g. Type='Customer';

Connection string generation

The following code shows how the C1MagentoConnectionStringBuilder class can be used to configure the connection string for Magento and consumed by the C1MagentoConnection class to create a connection to the server. Here, you can query the data.

//Create a connection string using C1MagentoConnectionStringBuilder

C1MagentoConnectionStringBuilder connBuilder= new C1MagentoConnectionStringBuilder();
connBuilder.Username = @”******";
connBuilder.Password = @"*******";
connBuilder.TokenType= @"****";
connBuilder.Url = @"http://****/****/****";
//Create and establish connection
C1MagentoConnection conn = new C1MagentoConnection(connBuilder)

Connection string literal

Alternatively, the connection string can be written directly as a string literal like in the code example below.

static string MagentoConnectionString = $”Url ='http://*.*.*.*';UserName='yourMagentoUserName';Password ='yourpassword';Token Type='tokentype'“;
C1MagentoConnection conn = new C1MagentoConnection(MagentoConnectionString )

OAuth-based authentication

Magento OAuth authentication is based on OAuth 1.0.

Connection string generation

The following code shows how the C1MagentoConnectionStringBuilder class can be used to configure the connection string for Magento and consumed by the C1MagentoConnection class to create a connection to the server. Here, you can query the data.

//Create a connection string using C1MagentoConnectionStringBuilder

C1MagentoConnectionStringBuilder connBuilder= new C1MagentoConnectionStringBuilder();
connBuilder.ConsumerKey= @”******";
connBuilder.ConsumerSecret= @"*******";
connBuilder.Verifier= @"****";
connBuilder.Url = @"http://****/****/****";
//Create and establish connection
C1MagentoConnection conn = new C1MagentoConnection(connBuilder)

Connection string literal

Alternatively, the connection string can be written directly as a string literal like in the code example below.

string MagentoConnection = $"Url='http://*.*.*.*;Consumer Key='*************';Consumer Secret='***********';Verifier='****************'“;

C1MagentoConnection conn = new C1MagentoConnection(MagentoConnection );