Azure Sql actual process of 3 - firewall configuration and debugging connection



  At this point the database instance has been completely started, of course, still can not connect, you need to complete the firewall settings, remote client debugging.

  

1, firewall configuration

  Click Favorites on the left side of the folder "SQL Database", you can see the SQL instance is already configured in SQL panel, as follows:

   

  

   Click example, to enter the detail page instance.

  

  

  Select "Set Server Firewall" on the toolbar. This opens the "Firewall Settings" page of the database server. In summary and configurations can enter this function.

  

  

  Click the "Add Client IP", customers will automatically be imported under the rules in the end ip panel recommended: If you click on the time that there is no automatic tick behind the client ip input box, it is recommended click "Add Client IP" again, In general this situation will rarely occur.

  

  

  Remember to click "Save" to save just ip configuration

  

  

2 , database web connection terminal debugging

  Returns the total database instance details page, click the "Query Editor (Preview)" menu, as follows:

        

  

  Enter the database logon in the "SQL Server Authentication" in the user name and password, and then click "OK", try to log database.

  

  

  The following error message:

Cannot open server 'databaseserver' requested by the login. 
Client with IP address '223.104.90.105' is not allowed to access the server.
To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range.
It may take up to five minutes for this change to take effect.

  

  这时,需要将web端ip设置进防火墙,步骤如图,点击“设置服务器防火墙 (databaseserver)” ,安装1的步骤手动设置防火墙。

 

  

  

  返回web登录界面,重新尝试登录。这时已经可以看到连接进入数据库的样子

  

  

3、数据库远程客户端调试连接

  在数据库概述面板中,复制服务器名称,方便远程客户端的连接。

  

  

  打开Windows本地的“Microsoft SQL Server Management Studio 18”工具,服务器类型设置为“数据库引擎”,身份验证选择“SQL Server 身份验证”。如图:

  

  点击连接,就可以进入连接界面。

  

  

4、数据库程序端配置方案

  进入“连接字符串界面”,可以看到该数据库所支持连接方案,如图:

 

  所支持的方式如下:

1)、ADO.NET (SQL 身份验证)

Server=tcp:databaseserver.database.chinacloudapi.cn,1433;Initial Catalog=mySampleDatabase;Persist Security Info=False;User ID=adminer;Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

 

2)、JDBC (SQL 身份验证)

jdbc:sqlserver://databaseserver.database.chinacloudapi.cn:1433;database=mySampleDatabase;user=adminer@databaseserver;password={your_password_here};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.chinacloudapi.cn;loginTimeout=30;

 

3)、ODBC (包括 Node.js) (SQL 身份验证)

Driver={ODBC Driver 13 for SQL Server};Server=tcp:databaseserver.database.chinacloudapi.cn,1433;Database=mySampleDatabase;Uid=adminer;Pwd={your_password_here};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;

 

4)、PHP (SQL 身份验证)

<?php
// PHP Data Objects(PDO) Sample Code:
try {
    $conn = new PDO("sqlsrv:server = tcp:databaseserver.database.chinacloudapi.cn,1433; Database = mySampleDatabase", "adminer", "{your_password_here}");
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
    print("Error connecting to SQL Server.");
    die(print_r($e));
}

// SQL Server Extension Sample Code:
$connectionInfo = array("UID" => "adminer", "pwd" => "{your_password_here}", "Database" => "mySampleDatabase", "LoginTimeout" => 30, "Encrypt" => 1, "TrustServerCertificate" => 0);
$serverName = "tcp:databaseserver.database.chinacloudapi.cn,1433";
$conn = sqlsrv_connect($serverName, $connectionInfo);
?>

 

5)、Go (SQL 身份验证)

// Go connection Sample Code:
package main
import (
    github.com/denisenkom/go-mssqldb
    database/sql
    context
    log
    fmt
    errors
)

var db *sql.DB
var server = "databaseserver.database.windows.net"
var port = 1433
var user = "adminer"
var password = "<your_password>"
var database = "mySampleDatabase"

func main() {
    // Build connection string
    connString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d;database=%s;",
        server, user, password, port, database)
    var err error
    // Create connection pool
    db, err = sql.Open("sqlserver", connString)
    if err != nil {
        log.Fatal("Error creating connection pool: ", err.Error())
    }
    ctx := context.Background()
    err = db.PingContext(ctx)
    if err != nil {
        log.Fatal(err.Error())
    }
    fmt.Printf("Connected!")
}

 

Guess you like

Origin www.cnblogs.com/Raodi/p/12339749.html