SQL Server Hook and operator connection in Airflow

2019-08-27 02:06发布

问题:

I am new to using airflow and what I need to do is to use MssqlHook or MssqlOperator but I do not know how.

By using hook and operator below code

hook = MsSqlHook(mssql_conn_id=ms_sql)

t2 = MsSqlOperator(
        task_id = 'sql-op',
        mssql_conn_id = ms_sql,
        sql = 'Select Current_date()',
        dag = dag)

in Airflow UI connections-

Conn Id - ms_sql
Conn Type -Microsoft SQL server
Host - host_name
schema- default
login- username
password- password
port - 14481

And when I do this the error is

Connection failed for unknown reason

How should I connect?