DataConnector | ComponentOne
ADO.NET provider for Magento / Creating Connection
In This Topic
    Creating Connection
    In This Topic

    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:

    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:

    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.

    C#
    Copy Code
    //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.

    C#
    Copy Code
    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.

    C#
    Copy Code
    //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.

    C#
    Copy Code
    string MagentoConnection = $"Url='http://***.***.***.***;Consumer Key='*************';Consumer Secret='***********';Verifier='****************'“;
    
    C1MagentoConnection conn = new C1MagentoConnection(MagentoConnection );