连接到 Azure SQL 数据仓库Connect to Azure SQL Data Warehouse

连接到 Azure SQL 数据仓库。Get connected to Azure SQL Data Warehouse.

查找服务器名称Find your server name

以下示例中的服务器名称是 samplesvr.database.chinacloudapi.cn。The server name in the following example is samplesvr.database.chinacloudapi.cn. 若要查找完全限定的服务器名称,请执行以下操作:To find the fully qualified server name:

  1. 转到 Azure 门户Go to the Azure portal.

  2. 单击“SQL 数据仓库”。Click on SQL data warehouses.

  3. 单击要连接到的数据仓库。Click on the data warehouse you want to connect to.

  4. 找到完整的服务器名称。Locate the full server name.

    完整服务器名称

支持的驱动程序和连接字符串Supported drivers and connection strings

Azure SQL 数据仓库支持 ADO.NETODBCPHPJDBCAzure SQL Data Warehouse supports ADO.NET, ODBC, PHP, and JDBC. 单击前述的某个驱动程序,查找最新版本和文档。To find the latest version and documentation, click on one of the preceding drivers. 若要自动生成通过 Azure 门户使用的驱动程序的连接字符串,请单击前述示例中的“显示数据库连接字符串”。To automatically generate the connection string for the driver that you are using from the Azure portal, click on the Show database connection strings from the preceding example. 下面也是一些示例,说明了每个驱动程序的连接字符串的样式。Following are also some examples of what a connection string looks like for each driver.

Note

请考虑将连接超时值设置为 300 秒,以便连接可以经受住短时间内不可用。Consider setting the connection timeout to 300 seconds to allow your connection to survive short periods of unavailability.

ADO.NET 连接字符串示例ADO.NET connection string example

Server=tcp:{your_server}.database.chinacloudapi.cn,1433;Database={your_database};User ID={your_user_name};Password={your_password_here};Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

ODBC 连接字符串示例ODBC connection string example

Driver={SQL Server Native Client 11.0};Server=tcp:{your_server}.database.chinacloudapi.cn,1433;Database={your_database};Uid={your_user_name};Pwd={your_password_here};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;

PHP 连接字符串示例PHP connection string example

Server: {your_server}.database.chinacloudapi.cn,1433 \r\nSQL Database: {your_database}\r\nUser Name: {your_user_name}\r\n\r\nPHP Data Objects(PDO) Sample Code:\r\n\r\ntry {\r\n   $conn = new PDO ( \"sqlsrv:server = tcp:{your_server}.database.chinacloudapi.cn,1433; Database = {your_database}\", \"{your_user_name}\", \"{your_password_here}\");\r\n    $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );\r\n}\r\ncatch ( PDOException $e ) {\r\n   print( \"Error connecting to SQL Server.\" );\r\n   die(print_r($e));\r\n}\r\n\rSQL Server Extension Sample Code:\r\n\r\n$connectionInfo = array(\"UID\" => \"{your_user_name}\", \"pwd\" => \"{your_password_here}\", \"Database\" => \"{your_database}\", \"LoginTimeout\" => 30, \"Encrypt\" => 1, \"TrustServerCertificate\" => 0);\r\n$serverName = \"tcp:{your_server}.database.chinacloudapi.cn,1433\";\r\n$conn = sqlsrv_connect($serverName, $connectionInfo);

JDBC 连接字符串示例JDBC connection string example

jdbc:sqlserver://yourserver.database.chinacloudapi.cn:1433;database=yourdatabase;user={your_user_name};password={your_password_here};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.chinacloudapi.cn;loginTimeout=30;

连接设置Connection settings

SQL 数据仓库在连接和创建对象期间标准化一些设置。SQL Data Warehouse standardizes some settings during connection and object creation. 这些设置不能重写,其中包括:These settings cannot be overridden and include:

数据库设置Database Setting Value
ANSI_NULLSANSI_NULLS ON
QUOTED_IDENTIFIERSQUOTED_IDENTIFIERS ON
DATEFORMATDATEFORMAT mdymdy
DATEFIRSTDATEFIRST 77

后续步骤Next steps

若要使用 Visual Studio 进行连接和查询,请参阅 Query with Visual Studio(使用 Visual Studio 进行查询)。To connect and query with Visual Studio, see Query with Visual Studio. 若要详细了解身份验证选项,请参阅 Authentication to Azure SQL Data Warehouse(通过 Azure SQL 数据仓库进行身份验证)。To learn more about authentication options, see Authentication to Azure SQL Data Warehouse.