Connect to Lakebase Data from PowerBuilder via ADO.NET
This article demonstrates using the CData ADO.NET Provider for Lakebase in PowerBuilder, showcasing the ease of use and compatibility of these standards-based controls across various platforms and development technologies that support Microsoft .NET, including Appeon PowerBuilder.
This article shows how to create a basic PowerBuilder application that uses the CData ADO.NET Provider for Lakebase to perform reads and writes.
- In a new WPF Window Application solution, add all the Visual Controls needed for the connection properties. Below is a typical connection string:
DatabricksInstance=lakebase;Server=127.0.0.1;Port=5432;Database=my_database;InitiateOAuth=GETANDREFRESH;
To connect to Databricks Lakebase, start by setting the following properties:
- DatabricksInstance: The Databricks instance or server hostname, provided in the format instance-abcdef12-3456-7890-abcd-abcdef123456.database.cloud.databricks.com.
- Server: The host name or IP address of the server hosting the Lakebase database.
- Port (optional): The port of the server hosting the Lakebase database, set to 5432 by default.
- Database (optional): The database to connect to after authenticating to the Lakebase Server, set to the authenticating user's default database by default.
OAuth Client Authentication
To authenicate using OAuth client credentials, you need to configure an OAuth client in your service principal. In short, you need to do the following:
- Create and configure a new service principal
- Assign permissions to the service principal
- Create an OAuth secret for the service principal
For more information, refer to the Setting Up OAuthClient Authentication section in the Help documentation.
OAuth PKCE Authentication
To authenticate using the OAuth code type with PKCE (Proof Key for Code Exchange), set the following properties:
- AuthScheme: OAuthPKCE.
- User: The authenticating user's user ID.
For more information, refer to the Help documentation.
- Add the DataGrid control from the .NET controls.
-
Configure the columns of the DataGrid control. Below are several columns from the Account table:
<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=ShipName}" Header="ShipName" Width="SizeToHeader" /> ... </DataGrid.Columns> </DataGrid> - Add a reference to the CData ADO.NET Provider for Lakebase assembly.
Connect the DataGrid
Once the visual elements have been configured, you can use standard ADO.NET objects like Connection, Command, and DataAdapter to populate a DataTable with the results of an SQL query:
System.Data.CData.Lakebase.LakebaseConnection conn conn = create System.Data.CData.Lakebase.LakebaseConnection(connectionString) System.Data.CData.Lakebase.LakebaseCommand comm comm = create System.Data.CData.Lakebase.LakebaseCommand(command, conn) System.Data.DataTable table table = create System.Data.DataTable System.Data.CData.Lakebase.LakebaseDataAdapter dataAdapter dataAdapter = create System.Data.CData.Lakebase.LakebaseDataAdapter(comm) dataAdapter.Fill(table) datagrid1.ItemsSource=table.DefaultView
The code above can be used to bind data from the specified query to the DataGrid.