この記事ではCData ADO.NET Provider for Azure Data Lake Storage を使ってPowerBuilder からAzure Data Lake Storage にアクセスする方法を説明します。
CData ADO.NET providers は、PowerBuilder を含むMicrosoft .NET をサポートするあらゆるプラットフォームまたは開発テクノロジーから使用できる、使いやすい標準準拠のデータプロバイダーです。 この記事では、CData ADO.NET Provider for Azure Data Lake Storage をPowerBuilder で使う方法について説明します。
CData ADO.NET Provider for Azure Data Lake Storage を使ってデータを取得し読み書きを実行する基本的なPowerBuilder アプリケーションを作成する方法について説明します。
- 新規WPF Window Application ソリューションで、接続プロパティに必要なすべてのビジュアルコントロールを追加します。一般的な接続文字列は次のとおりです:
Schema=ADLSGen2;Account=myAccount;FileSystem=myFileSystem;AccessKey=myAccessKey;InitiateOAuth=GETANDREFRESH
Authenticating to a Gen 1 DataLakeStore Account
Gen 1 uses OAuth 2.0 in Azure AD for authentication.
For this, an Active Directory web application is required. You can create one as follows:
To authenticate against a Gen 1 DataLakeStore account, the following properties are required:
- Schema: Set this to ADLSGen1.
- Account: Set this to the name of the account.
- OAuthClientId: Set this to the application Id of the app you created.
- OAuthClientSecret: Set this to the key generated for the app you created.
- TenantId: Set this to the tenant Id. See the property for more information on how to acquire this.
- Directory: Set this to the path which will be used to store the replicated file. If not specified, the root directory will be used.
Authenticating to a Gen 2 DataLakeStore Account
To authenticate against a Gen 2 DataLakeStore account, the following properties are required:
- Schema: Set this to ADLSGen2.
- Account: Set this to the name of the account.
- FileSystem: Set this to the file system which will be used for this account.
- AccessKey: Set this to the access key which will be used to authenticate the calls to the API. See the property for more information on how to acquire this.
- Directory: Set this to the path which will be used to store the replicated file. If not specified, the root directory will be used.
- .NET コントロールからDataGrid コントロールを追加します。
-
DataGrid コントロールのカラムを設定します。Account テーブルからいくつかのカラムを以下に示します:
<DataGrid AutoGenerateColumns="False" Margin="13,249,12,14" Name="datagrid1" TabIndex="70" ItemsSource="{Binding}"> <DataGrid.Columns> <DataGridTextColumn x:Name="idColumn" Binding="{Binding Path=Id}" Header="Id" Width="SizeToHeader" /> <DataGridTextColumn x:Name="nameColumn" Binding="{Binding Path=FullPath}" Header="FullPath" Width="SizeToHeader" /> ... </DataGrid.Columns> </DataGrid>
- CData ADO.NET Provider for Azure Data Lake Storage アセンブリへの参照を追加します。
DataGrid 接続
ビジュアルエレメントが設定されたら、Connection、Command、およびDataAdapter のような標準のADO.NET オブジェクトを使ってSQL クエリの結果をDataTable に表示することができます:
System.Data.CData.ADLS.ADLSConnection conn
conn = create System.Data.CData.ADLS.ADLSConnection(connectionString)
System.Data.CData.ADLS.ADLSCommand comm
comm = create System.Data.CData.ADLS.ADLSCommand(command, conn)
System.Data.DataTable table
table = create System.Data.DataTable
System.Data.CData.ADLS.ADLSDataAdapter dataAdapter
dataAdapter = create System.Data.CData.ADLS.ADLSDataAdapter(comm)
dataAdapter.Fill(table)
datagrid1.ItemsSource=table.DefaultView
上のコードは、指定したクエリからDataGrid にデータをバインドできます。