从iOS swift应用程序访问Azure SQL数据库表时出现问题。 [英] Problem accessing Azure SQL database table from iOS swift app.

查看:52
本文介绍了从iOS swift应用程序访问Azure SQL数据库表时出现问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个演示应用程序,用于对Azure Active Directory中的用户进行身份验证,并且能够与简易表进行同步。当我将Azure门户的App Service与SQL数据库连接时,然后在iOS swift应用程序中获取表数据会引发401错误。以下是
代码段。

I created a demo app that authenticates user from Azure Active Directory and able to perform sync with easy tables. When I connected App Service at Azure Portal with SQL database then fetching a table data in iOS swift app throws 401 error. Below is the code snippet.

client = MSClient ( applicationURLString:
" URL String"

let client = MSClient(applicationURLString: "URL String")

        managedObjectContext =( UIApplication 共享委托
as AppDelegate )。 managedObjectContext

        let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).managedObjectContext!

<跨度>&NBSP; &NBSP; &NBSP; &NBSP; self store =
MSCoreDataStore (managedObjectContext:managedObjectContext)

        self.store = MSCoreDataStore(managedObjectContext: managedObjectContext)

<跨度>&NBSP; &NBSP; &NBSP; &NBSP; client。 syncContext =
MSSyncContext
(委托: nil ,dataSource: self 商店,回调:
nil

        client.syncContext = MSSyncContext(delegate: nil, dataSource: self.store, callback: nil)

  &NBSP; &NBSP; &NBSP; self = client。 syncTable (withName:
" table name"

        self.table = client.syncTable(withName: "table name")

  &NBSP; &NBSP; &NBSP; <跨度>自 <跨度> refreshControl <跨度>? addTarget <跨度>( <跨度>自 ,操作:
#selector ActivityTableViewController .onRefresh( _ :)),用于:
UIControlEvents valueChanged

        self.refreshControl?.addTarget(self, action: #selector(ActivityTableViewController.onRefresh(_:)), for: UIControlEvents.valueChanged)

API调用(onRefresh调用):

self !。 pull (带有: self ?。查询(),queryId:
" AllRecords" ){

self.table!.pull(with: self.table?.query(), queryId: "AllRecords") {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; (错误) - > 无效

            (error) -> Void in

   &NBSP; &NBSP; &NBSP; &NBSP;  

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DispatchQueue main async {

            DispatchQueue.main.async {

<跨度>&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; UIApplication 共享 isNetworkActivityIndi​​catorVisible =
false

                UIApplication.shared.isNetworkActivityIndicatorVisible = false

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //在这里抛出401错误

            //throws 401 error here

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }

  &NBSP; &NBSP; &NBSP; }

我是Azure移动开发的新手。请说明为什么我无法访问SQL数据库。

I am new to Azure mobile development. Please suggest why I am not able to access SQL database.

推荐答案

您好iOSGuy,

Hi iOSGuy,

您是否可以验证"允许访问Azure服务"?已在防火墙中为Azure SQL Server实例启用。

Can you verify that the "Allow access to Azure Services" is enabled in the firewall for your Azure SQL Server instance.

Azure SQL Server安全性

或者您需要识别App Service的IP地址并将此IP列入白名单在防火墙ACL中。 

Or you need to identify the IP address for your App Service and whitelist this IP in the firewall ACL. 

如果您有任何其他问题,请与我们联系。

Please let me know if you have any additional questions.

谢谢,

Mike


这篇关于从iOS swift应用程序访问Azure SQL数据库表时出现问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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