无法创建链接到Snowflake的服务器
我按照我能找到的所有说明操作:
- 在我的SQL Server虚拟机上安装了最新的Snowflake 64位ODBC驱动程序
- 已为其创建系统dsn(填写了"用户"、"服务器"、"数据库"、"架构"、"仓库"、"角色"和"跟踪"字段)
- 在SQL Server中,对于MSDASQL链接服务器提供程序,启用了以下参数:嵌套查询、仅零级、允许进程内、支持‘LIKE’运算符
- 按照说明创建链接服务器
- Provider=Microsoft OLE DB Provider for ODBC驱动程序
- 数据源:我创建的系统DSN名称
- 安全:
- 将本地登录名"NT AUTHORITYSYSTEM"映射到远程用户名和密码(它们在我通过Web浏览器连接到Snowflake时有效)
- 单击‘使用登录的当前安全上下文进行操作’ 单击"确定"时,出现以下错误
解决方案
在链接服务器的安全选项卡中:
您已映射"NT AUTHORITYSYSTEM"(这是SQL服务帐户吗?)远程用户名和密码。
对于不在您选择的列表中的任何其他登录,使用该登录的当前安全上下文
发件人https://docs.microsoft.com/en-us/sql/relational-databases/linked-servers/create-linked-servers-sql-server-database-engine
使用登录的当前安全上下文 指定将使用列表中未定义的登录的当前登录安全上下文建立连接。如果使用Windows身份验证连接到本地服务器,您的Windows凭据将用于连接到远程服务器。如果使用SQL Server身份验证连接到本地服务器,则将使用登录名和密码连接到远程服务器。在这种情况下,远程服务器上必须存在具有完全相同名称和密码的登录名。
您可以将您的登录名映射到远程雪花用户名&;密码,或者选择
对于上面列表中未定义的登录,连接将: 使用此安全上下文创建,并在框中填写雪花的用户名和密码。/*
snowflake server=xyz12345.west-europe.azure.snowflakecomputing.com
snowflake user= testuser
snowflake password = Testuser1
*/
--system DSN for snowflake named SNOWFLAKEDSN [SnowflakeDSIIDriver, User: testuser, Server:xyz12345.west-europe.azure.snowflakecomputing.com, Database:DEMO_DB, Tracing:4 (default)]
--Note: Attempting any of the commands with a wrong password could lock temporarily the snowflake account. tread carefully
--snowflake without linked server
--openrowset using dsn
SELECT *
FROM OPENROWSET('MSDASQL', 'DSN=SNOWFLAKEDSN;UID=testuser;PWD=Testuser1', 'select cast(TABLE_NAME as varchar(100)) as tablename from demo_db.information_schema.tables');
--openrowset using dsn2 , format= provider, DSN;uid;password, query
SELECT *
FROM OPENROWSET('MSDASQL', 'SNOWFLAKEDSN';'testuser';'Testuser1', 'select cast(TABLE_NAME as varchar(100)) as tablename from demo_db.information_schema.tables');
--openrowset without dsn
SELECT *
FROM OPENROWSET('MSDASQL', 'DRIVER=SnowflakeDSIIDriver;SERVER=xyz12345.west-europe.azure.snowflakecomputing.com;UID=testuser;PWD=Testuser1', 'select cast(TABLE_NAME as varchar(100)) as tablename from demo_db.information_schema.tables');
GO
--linked server using DSN
EXEC master.dbo.sp_addlinkedserver @server = N'SNOWFLAKE_WITH_DSN', @srvproduct=N'', @provider=N'MSDASQL', @datasrc=N'SNOWFLAKEDSN';
/*every login of the sql instance connects to snowflake as testuser*/
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'SNOWFLAKE_WITH_DSN',@useself=N'False',@locallogin=NULL,@rmtuser=N'testuser',@rmtpassword='Testuser1';
--linked server without DSN, name of linked server is SNOWFLAKE_WITHOUT_DSN
EXEC master.dbo.sp_addlinkedserver @server = N'SNOWFLAKE_WITHOUT_DSN', @srvproduct=N'', @provider=N'MSDASQL', @provstr=N'DRIVER=SnowflakeDSIIDriver;SERVER=xyz12345.west-europe.azure.snowflakecomputing.com';
/*every login of the sql instance connects to snowflake as testuser*/
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'SNOWFLAKE_WITHOUT_DSN',@useself=N'False',@locallogin=NULL,@rmtuser=N'testuser',@rmtpassword='Testuser1';
--linked server without DSN, hardcoded snowflake creds in the provider string (at own risk)
/*
EXEC master.dbo.sp_addlinkedserver @server = N'SNOWFLAKE_WITHOUT_DSN_HARDCODED_CREDS', @srvproduct=N'', @provider=N'MSDASQL', @provstr=N'DRIVER=SnowflakeDSIIDriver;SERVER=xyz12345.west-europe.azure.snowflakecomputing.com;UID=testuser;PWD=Testuser1';
/*creds hardcoded in the connection string, logins use their own security context */
/* caveat: this worked ok for windows authenticated logins. sql authenticated logins could not use the linked server, not tested with msdasql in process... */
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'SNOWFLAKE_WITHOUT_DSN_HARDCODED_CREDS',@useself=N'True',@locallogin=NULL,@rmtuser=NULL,@rmtpassword=NULL;
*/
相关文章