从 PowerApps 连接到 SQL ServerConnect to SQL Server from PowerApps

SQL Server 图标

在 Azure 或本地数据库中连接到 SQL Server,以便在 PowerApps 中显示其中的信息。Connect to SQL Server, in either Azure or an on-premises database, so that you can display information from it in PowerApps.

先决条件Prerequisites

  • 注册 PowerApps、安装 PowerApps Studio,打开该程序,然后提供过去注册所用的同一凭据进行登录。Sign up for PowerApps, install PowerApps Studio, open it, and then sign in by providing the same credentials that you used to sign up.
  • 使用主键收集包含至少一个表的数据库的以下信息:Gather the following information for a database that contains at least one table with a primary key:

    • 数据库的名称the name of the database
    • 托管数据库的服务器的名称the name of the server on which the database is hosted
    • 用于连接数据库的一个有效用户名和密码a valid user name and password to connect to the database
    • 连接数据库所需的身份验证类型the type of authentication needed to connect to the database

      如果没有此信息,请询问要使用的数据库的管理员。If you don't have this information, ask the administrator of the database that you want to use.

  • 对于本地数据库,标识与你共享的数据网关(或创建一个数据网关)。For an on-premises database, identify a data gateway that was shared with you (or create one).

    注意:只能在用户的默认环境中创建和使用网关和本地连接。Note: Gateways and on-premises connections can only be created and used in the user's default environment.

自动生成应用Generate an app automatically

  1. 在 PowerApps Studio 中,单击或点击“文件”菜单(沿左边缘)上的“新建”。In PowerApps Studio, click or tap New on the File menu (along the left edge).

    “文件”菜单上的“新建”选项

  2. 在“开始处理数据”下,单击或点击连接器行末尾的右箭头。Under Start with your data, click or tap the right arrow at the end of the row of connectors.
  3. 如果已有要使用的数据库的连接,单击或点击此连接,然后跳到此过程的步骤 7。If you already have a connection to the database that you want to use, click or tap it, and then skip to step 7 in this procedure.
  4. 单击或点击“新建连接”,然后单击或点击“SQL Server”。Click or tap New connection, and then click or tap SQL Server.

    添加 SQL Server 连接

  5. 执行以下任一步骤:Perform either of these steps:

    • 指定“直接连接(云服务)”,然后键入或粘贴要使用的数据库的服务器名称、数据库名称、用户名和密码。Specify Connect directly (cloud services), and then type or paste the server name, the database name, the user name, and the password for the database that you want to use.

      连接到 Azure 中的数据库

    • 指定“使用本地数据网关连接”,然后键入或粘贴要使用的数据库的服务器名称、数据库名称、用户名和密码,并指定身份验证类型和网关。Specify Connect using on-premises data gateway, type or paste the server name, the database name, the user name, and the password for the database that you want to use, and specify the authentication type and the gateway.

      连接到本地数据库

      注意:如果没有网关,可安装网关,然后单击或点击“刷新网关列表”。Note: If you don't have a gateway, install one, and then click or tap Refresh gateway list.

  6. 单击或点击“连接”。Click or tap Connect.
  7. 单击或点击“选择数据集”下的选项,单击或点击“选择表”下的选项,然后单击或点击“连接”。Click or tap an option under Choose a dataset, click or tap an option under Choose a table, and then click or tap Connect.

    PowerApps 可创建在三个屏幕中显示数据的应用。PowerApps creates an app that shows data on three screens. 启发会建议显示的数据属性,但可能需要自定义 UI 以满足你的需求。Heuristics suggest what kind of data to show, but you might need to customize the UI to suit your needs.

  8. 通过使用类似通过 Excel 创建应用中介绍的技术来自定义应用,开始更改应用布局。Customize the app by using techniques that are similar to those that Create an app from Excel describes, starting with changing the app layout.

从头开始构建应用Build an app from scratch

  1. 使用注册 PowerApps 所用的同一帐户登录 powerapps.comSign in to powerapps.com with the same account that you used to sign up for PowerApps.
  2. 在左侧导航栏中,单击或点击“连接”:In the left navigation bar, click or tap Connections:

    管理连接

  3. 在右上角,单击或点击“新建连接”,然后单击或点击“SQL Server”。In the upper-right corner, click or tap New connection, and then click or tap SQL Server.
  4. 执行以下任一步骤:Perform either of these steps:

    • 指定“直接连接(云服务)”,然后键入或粘贴要使用的数据库的服务器名称、数据库名称、用户名和密码。Specify Connect directly (cloud services), and then type or paste the server name, the database name, the user name, and the password for the database that you want to use.

      连接到 Azure 中的数据库

    • 指定“使用本地数据网关连接”,然后键入或粘贴要使用的数据库的服务器名称、数据库名称、用户名和密码,并指定身份验证类型和网关。Specify Connect using on-premises data gateway, type or paste the server name, the database name, the user name, and the password for the database that you want to use, and specify the authentication type and the gateway.

      连接到 Azure 中的数据库

      注意:如果没有网关,可安装网关,然后单击或点击顺时针图标来刷新列表。Note: If you don't have a gateway, install one, and then click or tap the clockwise icon to refresh the list.

  5. 单击或点击“创建”以创建连接。Click or tap Create to create the connection.
  6. 通过使用类似从头开始创建应用中介绍的技术来创建应用。Create an app by using techniques that are similar to those that Create an app from scratch describes.

更新现有应用Update an existing app

  1. 在 PowerApps Studio 中,打开想要更新的应用。In PowerApps Studio, open the app that you want to update.
  2. 在功能区中的“视图”选项卡上,单击或点击“数据源”。Click or tap Data sources on the View tab of the ribbon.
  3. 单击或点击右侧窗格中的“添加数据源”。In the right-hand pane, click or tap Add a data source.

    添加数据源

  4. 单击或点击“新连接”,单击或点击“SQL Server”,然后单击或点击“连接”。Click or tap New connection, click or tap SQL Server, and then click or tap Connect.
  5. 执行以下任一步骤:Perform either of these steps:

    • 指定“直接连接(云服务)”,然后键入或粘贴要使用的数据库的服务器名称、数据库名称、用户名和密码。Specify Connect directly (cloud services), and then type or paste the server name, the database name, the user name, and the password for the database that you want to use.

      连接到 Azure 中的数据库

    • 指定“使用本地数据网关连接”,然后键入或粘贴要使用的数据库的服务器名称、数据库名称、用户名和密码,并指定身份验证类型和网关。Specify Connect using on-premises data gateway, type or paste the server name, the database name, the user name, and the password for the database that you want to use, and specify the authentication type and the gateway.

      连接到 Azure 中的数据库

      注意:如果没有网关,可安装网关,然后单击或点击圆形图标来刷新列表。Note: If you don't have a gateway, install one, and then click or tap the circular icon to refresh the list.

  6. 单击或点击“连接”。Click or tap Connect.
  7. 单击或点击“选择数据集”下的选项。Under Choose a dataset, click or tap an option.
  8. 在“选择表”下,选中一个或多个复选框,然后单击或点击“连接”。Under Choose a table, select one or more checkboxes, and then click or tap Connect.

后续步骤Next steps