简体   繁体   English

使用 Azure 应用服务连接到 SQL 服务器数据库

[英]Connect to SQL Server database with Azure App Service

I'm deploying an website for my company and it was, originally, hosted in an on-premise server.我正在为我的公司部署一个网站,它最初托管在本地服务器中。 Now I want to upload it to the cloud (Azure App Service) but I'm having some issues concerning the database's connection string.现在我想将它上传到云(Azure 应用服务) ,但我遇到了一些关于数据库连接字符串的问题。

While the website was being developed, I used to connect to the SQL Server Database with user authentication via PHP:在开发网站时,我曾经通过 PHP 使用用户身份验证连接到 SQL 服务器数据库:

$connectionInfo = array('Database'=>"database_name", "CharacterSet"=>"UTF-8");
$connCRM = sqlsrv_connect($serverName, $connectionInfo);

Now that it's in the process of deployment, I want to connect to the database with a db user and password:现在它正在部署过程中,我想使用 db 用户和密码连接到数据库:

$connectionInfo = array('Database'=>"database_name", "CharacterSet"=>"UTF-8", "UID"=>"user", "PWD"=>"pass");
$connCRM = sqlsrv_connect($serverName, $connectionInfo);

Considering I'm not connected to the VPN (the website is not located locally anymore), it seems like it can't find my server, even though I'm accessing it through TS (in the destination server).考虑到我没有连接到 VPN(该网站不再位于本地),它似乎找不到我的服务器,即使我通过 TS(在目标服务器中)访问它。

Already tried to authenticate in SSMS with this user and password and it's working.已经尝试使用此用户和密码在 SSMS 中进行身份验证,并且它正在工作。

Error message: Array ( [0] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired [message] => [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired ) [1] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 11001 [code] => 11001 [2] => [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2AF9 [message] => [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2AF9 ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 11001 [code] => 11001 [2] => [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if Z9778840A0100C错误消息: Array ( [0] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft] [ODBC Driver 17 for SQL服务器]登录超时[消息] => [Microsoft][ODBC Driver 17 for SQL 服务器]登录超时)[1] => 数组([0] => 08001 [SQLSTATE] => 08001 [1] => 11001 [code] => 11001 [2] => [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2AF9 [message] => [Microsoft][ODBC Driver 17 for Z9778840A0100CB30C982876741B0B5A2AFxZServer]TCP Provider: Error code 0x2AF9 ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 11001 [code] => 11001 [2] => [Microsoft][ODBC Driver 17 for SQL Server]A 网络- 与 SQL 服务器建立连接时发生了相关或特定于实例的错误。未找到或无法访问服务器。检查实例名称是否正确以及 Z9778840A0100C B30C982876741B0B5A2Z Server is configured to allow remote connections. B30C982876741B0B5A2Z 服务器配置为允许远程连接。 For more information see SQL Server Books Online.有关详细信息,请参阅 SQL 服务器联机丛书。 [message] => [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. [消息] => [Microsoft][适用于 SQL 服务器的 ODBC 驱动程序 17]与 SQL 服务器建立连接时发生网络相关或特定于实例的错误。 Server is not found or not accessible.服务器未找到或无法访问。 Check if instance name is correct and if SQL Server is configured to allow remote connections.检查实例名称是否正确以及 SQL 服务器是否配置为允许远程连接。 For more information see SQL Server Books Online.有关详细信息,请参阅 SQL 服务器联机丛书。 ) ) ) )

Your App Service is hosted in Azure, so it is indide Azure network, and you are trying to connect to a database server inside your organization network(since you indicate it is on-prem), so unless you configure your org firewall to allow inbound connection on the port in which db server is listening, connection would not be established.您的应用服务托管在 Azure 中,因此它位于 Azure 网络中,并且您正在尝试连接到组织网络内的数据库服务器(因为您表示它是本地的),所以除非您将组织防火墙配置为允许入站数据库服务器正在侦听的端口上的连接,连接将不会建立。 If your SQL Server is using default port, you need to allow inbound on port 1433.如果您的 SQL 服务器使用默认端口,则需要在端口 1433 上允许入站。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure app service Web API connect to a SQL Server database, with Azure AD account/windows authentication - Azure app service Web API connect to a SQL Server database, with Azure AD account/windows authentication 连接到Sql Server 2014数据库到Azure VM - Connect to Sql Server 2014 database into Azure VM Azure-应用程序服务-移动应用程序快速入门-连接数据库 - Azure - App Service - Mobile App Quickstart - Connect a Database 如何将Azure Web App连接到Azure SQL数据库 - How to Connect Azure Web App to Azure SQL Database 如何将我的应用程序连接到 SQL Server 数据库? - How to connect my app to a SQL Server database? React 应用程序 - 无法连接到 SQL Server 数据库 - React app - unable to connect to SQL Server database 将 Azure 应用服务中的连接字符串更改为指向外部 SQL 服务器数据库 - Changing connection string in Azure app service to point to external SQL server database 从Office 365连接到Azure SQL数据库/ SQL Server - Connect to a Azure SQL Database/SQL Server from Office 365 通过代理服务器连接到Azure上的SQL Server数据库 - Connect to SQL Server database on Azure through a proxy server Windows Azure Web服务,无法连接到SQL数据库 - Windows Azure Web Service, Fails to Connect to SQL Database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM