使用Windows服务访问Azure SQL数据库 [英] Accessing Azure SQL Database with Windows Service

查看:59
本文介绍了使用Windows服务访问Azure SQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Azure的新手.按照Microsoft的教程,我下载了Xamarin.Forms的"TodoAzure"客户端项目以及相应的后端项目.我还设置了Azure Web应用程序并发布了后端代码.一切正常.

我想知道的是如何从与客户端应用程序完全不同的来源访问Azure云数据库(大概使用Web应用程序)-我想使用Windows服务进行访问.我已经在台式计算机上运行了该服务,并且该服务可以访问本地 SQL数据库.该数据库的某些部分应上载到Azure云数据库,以便该数据在移动(Xamarin)应用程序中可见.

是否有最佳做法?我找不到任何合适的例子.我只需要一个链接或使用哪个软件包的描述.

解决方案

访问Azure SQL数据库与访问本地SQL Server几乎相同.如果您希望快速入门,可以

  • 将用户添加到桌面应用程序的数据库中.您可以使用SSMS,Visual Studio或门户中提供的查询编辑器.用于

  • I am new to Azure. Following the tutorials of Microsoft I have downloaded the "TodoAzure" Client project for Xamarin.Forms as well as the corresponding backend project. I also set up the Azure web app and published the backend code. This works all well as expected.

    What I would like to know is how I can access the Azure cloud database (presumably using the web app) from a completely different source than the client app - I would like to access it with a windows service. I already have this service that runs on my desktop computer, and this service has access to a local SQL database. Some parts of this database should be uploaded to the Azure cloud database, so that this data becomes visible in the mobile (Xamarin) app.

    Is there a best-practice on how to do this? I can't find any suitable examples. I need only a link or a description on which packages to use.

    解决方案

    Accessing an Azure SQL database is almost the same as accessing an onprem SQL Server. If you would like a quickstart, you can find one here, but your existing code should work if it is connecting to your local instance.

    There are a couple steps to change over the connection.

    1. The biggest difference is that you must add your local IP address to the firewall in your Azure SQL Server. You can get your IP address by typing "What's my ip" into your browser or clicking "Add Client IP" in the portal. Make sure to save your changes.
    2. Add a user to your database for your desktop app. You can use SSMS, Visual Studio, or there is a query editor available in the portal. The command to add a user to your Azure SQL database is CREATE USER user_name WITH PASSWORD = 'strong_password';. You can add users to the master database as you would in SQL Server, but it is better in Azure SQL to add them to specific DBs. You will then need to give it permissions, usually db_datareader and db_datawriter if you want it to be able to edit the data. The command for this is ALTER ROLE db_datawriter ADD MEMBER user_name;.

    3. Get your connection string and replace the one in your app. You can either change the server and database in your current string, or you can grab a fresh copy from the database's blade in the portal. Make sure to update the username and password with the ones you created.

    这篇关于使用Windows服务访问Azure SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆