简体   繁体   English

直接连接到 SQL Azure 还是通过 API 服务层连接?

[英]Direct connect to SQL Azure vs connection via API service layer?

Currently our DB works in customer's local network and we have client app on C# to consume data.目前我们的数据库在客户的本地网络中工作,我们在 C# 上有客户端应用程序来使用数据。 Due to some business needs, we got order to start moving everything to Azure.由于某些业务需要,我们接到命令开始将所有内容迁移到 Azure。 DB will be moving to Azure SQL. DB 将迁移到 Azure SQL。

We had discussion about accessing DB.我们讨论了访问数据库。 There are two points:有两点:

  1. One guy said that we have to add one more layer between our app (that will be working outside Azure at end-user PCs) and SQL Azure.一个人说我们必须在我们的应用程序(将在最终用户 PC 上的 Azure 之外工作)和 SQL Azure 之间再添加一层。 In other words he suggested adding API service that will be translated all requests to DB, ie app(on-premises) -> API service (on Azure)-> SQL Azure .换句话说,他建议添加将所有请求转换为 DB 的 API 服务,即app(on-premises) -> API service (on Azure)-> SQL Azure This approach looks more reliable and secure, since we are hiding SQL Azure behind facade of API service and the app talks to our API service only.这种方法看起来更可靠和安全,因为我们将 SQL Azure 隐藏在 API 服务的外观后面,并且应用程序仅与我们的 API 服务对话。 It looks more like a reverse proxy.它看起来更像是一个反向代理。 Obviously, behind this API we can build more sophisticated structure of DBs.显然,在这个 API 背后,我们可以构建更复杂的 DB 结构。
  2. Another guy suggested connecting directly to DB, ie app(on-premises) -> SQL Azure .另一个人建议直接连接到数据库,即app(on-premises) -> SQL Azure So far we don't have any plans to change structure of DB or even increase count of DBs.到目前为止,我们没有任何改变数据库结构甚至增加数据库数量的计划。 He claims it more simple and we can secure our connection the same way.他声称这更简单,我们可以用同样的方式保护我们的连接。 Having additional service that just re-translates our queries to DB and back looks like wasting time.In the future, if needed, we would add this API.有额外的服务只是将我们的查询重新转换到数据库并返回看起来是在浪费时间。将来,如果需要,我们会添加这个 API。

What would you select and recommend, and why ?你会选择和推荐什么,为什么?

Few notes:几点注意事项:

  • We are going to use Azure AD to authenticate users.我们将使用 Azure AD 对用户进行身份验证。
  • Our application will be moving to Azure too, but later (in 1-2 years), we have plans to create REST API and move to thin client instead of fat client we have right now.我们的应用程序也将迁移到 Azure,但稍后(1-2 年),我们计划创建 REST API 并迁移到瘦客户端而不是我们现在拥有的胖客户端。
  • Good performance is our goal, we don't want to add extra things that can decrease it, but security is our most important goal as well.良好的性能是我们的目标,我们不想添加额外的东西来降低性能,但安全性也是我们最重要的目标。

Certainly an intermediate layer is one way to go.当然,中间层是一种方法。 There isn't enough detail to be sure, but I wonder why you don't try the second option.没有足够的细节可以确定,但我想知道您为什么不尝试第二个选项。 Usually some redevelopment is normal.通常一些重建是正常的。 But if you can get away without it, and you get sufficient performance then that's even better.但是,如果您不用它就可以逃脱,并且获得足够的性能,那就更好了。

I hope this helps.我希望这有帮助。 Thank you.谢谢你。 Guy盖伊

If your application is not just a prototype (it sounds like it is not), then I advise you to build the intermediate API.如果您的应用程序不仅仅是一个原型(听起来好像不是),那么我建议您构建中间 API。 The primary reasons for this are:造成这种情况的主要原因是:

Flexibility灵活性

Rolling out a new version of an API is simple: You have either only one deployment or you have something like Octopus Deploy that deploys to a few instances at the same time for you.推出新版本的 API 很简单:您要么只有一个部署,要么拥有像Octopus Deploy这样的东西,可以同时为您部署到几个实例。 Deploying client applications is usually much more involved: Creating installers, distributing them, making sure users install them, etc.部署客户端应用程序通常更多地参与:创建安装程序,分发它们,确保用户安装它们,等等。

If you build the API, you will be able to make changes to the DB and hide these changes from the client applications by just modifying the API implementation, but keeping the API interfaces the same.如果您构建 API,您将能够对数据库进行更改,并通过修改 API 实现对客户端应用程序隐藏这些更改,但保持 API 接口相同。 Moving forward, this will simplify the tasks for your team considerably.展望未来,这将大大简化您团队的任务。

Security安全

As soon as you have different roles/permissions in your system, you will need to implement them with DB security features if you connect to the DB directly.一旦您的系统中有不同的角色/权限,如果您直接连接到数据库,您将需要使用数据库安全功能来实现它们。 This may work for simple cases, but even there it is a pain to manage.这可能适用于简单的情况,但即使在那里管理也很痛苦。

With an API, you can implement authorization in the API using C#.通过 API,您可以使用 C# 在 API 中实现授权。 Like this, you can build whatever you need and you're not restricted by the security features the DB offers.像这样,您可以构建您需要的任何东西,并且不受 DB 提供的安全功能的限制。

Also, if you don't take extra care about this, you may end up exposing the DB credentials to the client app, which will be a major security flaw.此外,如果您不特别注意这一点,您最终可能会将数据库凭据暴露给客户端应用程序,这将是一个主要的安全漏洞。

Conclusion结论

Build the intermediate API.构建中间 API。 Except you have strong reasons not to.除非你有充分的理由不这样做。 As always with architecture considerations, I'm sure there are cases where the above points don't apply.与架构方面的考虑一样,我确信在某些情况下上述几点不适用。 Just make sure you understand all the implications if you decide to go the direct route.如果您决定走直接路线,请确保您了解所有含义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过WCF服务使用连接字符串建立与Azure SQL数据库的连接的问题 - Issues establishing a connection to Azure SQL Database using Connection string via a WCF Service 在vNet性能内与在vNet外具有Azure SQL连接的Azure Web App PaaS(应用服务计划) - Azure Web App PaaS (App Service Plan) with Azure SQL connection inside vNet performance vs outside vNet Azure 应用服务 (ASE) SQL Azure 连接 - Azure app service (ASE) SQL Azure connection Azure VM无法连接到Azure SQL服务 - Azure VM Fails to Connect to Azure SQL Service 使用Azure服务总线而无法实现“直接” Internet连接,SendVia? - Use Azure Service Bus without 'direct' internet connection possible, SendVia? Azure SQL API 与 Azure Mongo API - Azure SQL API vs Azure Mongo API 无法在 VS 中的 CDC 控制任务中将 azure sql db 连接为连接管理器 - Can't connect azure sql db as connection manager in CDC control task in VS 通过Java客户端连接Azure服务总线 - Connection Azure service bus via Java client Azure app service Web API connect to a SQL Server database, with Azure AD account/windows authentication - Azure app service Web API connect to a SQL Server database, with Azure AD account/windows authentication Azure Mqtt 直接连接 - Azure Mqtt Direct Connection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM