DataConnector
接続の作成
ADO.NET provider for Magento > 接続の作成

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 C1MagentoConnectionStringBuilder class can be used to configure the connection string for Magento and consumed by C1MagentoConnection class to create a connection to the server. Here, you can query the data.

C#
コードのコピー
//接続文字列を作成します。 

using C1MagentoConnectionStringBuilder

C1MagentoConnectionStringBuilder connBuilder= new C1MagentoConnectionStringBuilder();
connBuilder.Username = @”******";
connBuilder.Password = @"*******";
connBuilder.TokenType= @"****";
connBuilder.Url = @"http://****/****/****";

//接続を作成して設定します。
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#
コードのコピー
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 C1MagentoConnectionStringBuilder class can be used to configure the connection string for Magento and consumed by C1MagentoConnection class to create a connection to the server. Here, you can query the data.

C#
コードのコピー
//接続文字列を作成します。 

using C1MagentoConnectionStringBuilder

C1MagentoConnectionStringBuilder connBuilder= new C1MagentoConnectionStringBuilder();
connBuilder.ConsumerKey= @”******";
connBuilder.ConsumerSecret= @"*******";
connBuilder.Verifier= @"****";
connBuilder.Url = @"http://****/****/****";

//接続を作成して設定します。
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#
コードのコピー
string MagentoConnection = $"Url='http://***.***.***.***;Consumer Key='*************';Consumer Secret='***********';Verifier='****************'“;

C1MagentoConnection conn = new C1MagentoConnection(MagentoConnection );