sql-server - 创建了到 Azure 的远程服务器链接,但未显示 dbo 架构

标签 sql-server azure

我正在开发一个 Web 应用程序,该应用程序在生产中连接到 Azure 数据库,但在我的本地环境中连接到在 Docker 中运行的 SQL Server。我希望我的本地数据库链接到 Azure 数据库,以便我可以轻松地从生产环境复制数据。我能够通过这些命令成功链接:

EXEC sp_addlinkedserver
  @server='remote',
  @srvproduct='',     
  @provider='sqlncli',
  @datasrc='mydb.database.windows.net',
  @location='',
  @provstr='',
  @catalog='mydb';

EXEC sp_addlinkedsrvlogin 
  @rmtsrvname = 'remote',
  @useself = 'false',
  @rmtuser = 'my_username',
  @rmtpassword = 'my_password';

EXEC sp_serveroption 'remote', 'rpc out', true;

...但是,尽管我可以连接并使用应用程序本身使用的相同用户名和密码,但我无法在 dbo 架构中看到我的对象,只能看到 sysINFORMATION_SCHEMA

为什么我在链接到远程 Azure 数据库时无法看到 [remote].[mydb].[dbo].* 对象?尝试选择时出现此错误:

Msg 7314, Level 16, State 1, Line 1 The OLE DB provider "MSOLEDBSQL" for linked server "remote" does not contain the table ""mydb"."dbo"."my_table"". The table either does not exist or the current user does not have permissions on that table.

最佳答案

Have you looked at the table's permissions?

这似乎是权限问题。您的查询是正确的。

作为一条建议,请尝试使用已被授予对特定表/数据库的选择权限的特定用户连接服务器。

GRANT select ON DATABASE::database_name TO username;
GO

来自 Azure SQL 数据库的数据:

enter image description here

链接服务的输出:

enter image description here

关于sql-server - 创建了到 Azure 的远程服务器链接,但未显示 dbo 架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74408385/

相关文章:

c# - Asp.Net Mvc 5 Azure Active Directory 获取用户配置文件图像并将其保存在服务器上

reactjs - 如何在azure msal React中处理 token 过期?

sql-server - Excel VBA 到 SQL Server(无需 SSIS)

asp.net - SqlConnection 本地主机失败的用户名

c# - 如何获取特定机器的 SqlInstances 列表

azure - 如何在Azure搜索中使用top和skip来更正分页?

mysql - MySQL中Rank和DenseRank的实现

SQL DELETE 语句解释

wordpress - 使用 AWS 将 Wordpress 作为服务上的应用程序而不是虚拟机上运行

django - 如何对 Azure Blob 存储的 fsspec 进行身份验证