【问题标题】:TCP Error: ODBC connection with Azure SQL DatabaseTCP 错误:与 Azure SQL 数据库的 ODBC 连接
【发布时间】:2015-05-06 02:22:26
【问题描述】:

通过 php 交换为我的应用程序使用 Azure SQL 数据库。我有一个在本地运行的 MSSQL express 服务器,但是当我迁移到 Azure 时,我收到了一个连接错误:

Warning: odbc_connect(): SQL error: [Microsoft][SQL Server Native Client 11.0]TCP Provider: No such host is known. , SQL state 08001 in SQLConnect in C:\wamp\www\UnitySQL\connect.php on line 13

我的代码如下(更改了登录详细信息但格式相同):

<?php 
    $username = $_REQUEST['username'];
    $password = $_REQUEST['password'];

    $user = 'Login@Azure';
    $pass = 'azure';
    $server = 'azure.database.secure.windows.net,port';
    $database = 'db';


// No changes needed from now on
    $connection_string = "DRIVER={SQL Server Native Client 11.0};;SERVER=$server;DATABASE=$database";
    $conn = odbc_connect($connection_string,$user,$pass);
    $q = "select top 1 u.First, u.UserEmail, u.UserTelephone, u.UserId, MAX
(us.session) as sessionid, us.LastQuestion as LastQuestion from [user] as u LEFT OUTER join usersession as us
On u.UserId = us.userid

where UserEmail='$username' AND UserTelephone='$password'
group by u.[First], u.UserEmail, u.UserTelephone, u.UserId, LastQuestion
Order by sessionid DESC";
    $result = odbc_exec($conn,$q);
    $num_rows = odbc_num_rows($result);

    if($num_rows > 0)
    {
        $row = odbc_fetch_array($result);
        echo "First=". $row['First'] . "/" . "UserId=" . $row['UserId'] . "/" . "SessionId=" . $row['sessionid'] . "/" . "LastQuestion=" . $row['LastQuestion'] . "/" . "UserEmail=" . $row['UserEmail']. "/" . "UserTelephone=" . $row['UserTelephone'];
    }
?>

【问题讨论】:

    标签: php azure azure-sql-database


    【解决方案1】:

    您的 $server 设置不正确。而不是

    $server = 'azure.database.secure.windows.net,port';
    

    试试

    $server = 'tcp:<YOUR_SRV_NAME>.database.windows.net,1433';
    

    替换为您的 SQL 数据库服务器的名称。 如需更多信息,请查看this tutorial

    【讨论】:

      猜你喜欢
      • 2013-07-17
      • 1970-01-01
      • 1970-01-01
      • 2020-10-20
      • 2010-11-13
      • 2013-06-09
      • 1970-01-01
      • 1970-01-01
      • 2016-08-13
      相关资源
      最近更新 更多