这是我正在使用的方法。
try
{
List<Patient> pList = await App.MobileService.GetTable<Patient>().Where(
patient => patient.id == 1).ToListAsync();
foreach (Patient p in pList)
{
System.Diagnostics.Debug.WriteLine("{0}, {1}", p.id, p.first_name);
}
}
catch (Exception err)
{
System.Diagnostics.Debug.WriteLine("ERROR! : {0}", err.Message);
}
这是患者实体。
class Patient
{
public int id { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public string middle_name { get; set; }
public string nirc { get; set; }
public int bed_id { get; set; }
}
这是我得到的错误。
An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'System.Net.WebException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.DLL and wasn't handled before a managed/native boundary
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in Microsoft.Azure.Zumo.WindowsPhone8.Managed.DLL and wasn't handled before a managed/native boundary
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
A first chance exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
当我将我的方法包装在 TryCatch 中时,我收到此消息
Error : The request could not be completed. ()
这是堆栈错误消息
at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.CreateMobileServiceException(String errorMessage, IServiceFilterRequest request, IServiceFilterResponse response)
at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.ThrowInvalidResponse(IServiceFilterRequest request, IServiceFilterResponse response, JToken body)
at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.<RequestAsync>d__f.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<SendReadAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.<EvaluateQueryAsync>d__3`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.WindowsAzure.MobileServices.MobileServiceTableQuery`1.<ToListAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at PhoneApp1.MainPage.<populate>d__0.MoveNext()
有几点需要注意。
- 权限设置为
Anybody with the Application Key
- 我添加了参考
Windows Azure Mobile Services Managed Client
- 我已经在 App.XAML.CS 中插入了这段代码。
using Microsoft.WindowsAzure.MobileServices;
- 我已经将从该网站获取的这段代码放在 App.XAML.CS 中。
public static MobileServiceClient MobileService = new MobileServiceClient( AppUrl, AppKey );
为什么我无法连接到我的数据库?我已经尝试在 Windows Store 应用程序上运行这些代码并且它有效。以前我做过完全相同的事情,而且效果也很好。