简单的MVC API无法正常工作

时间:2015-06-27 13:20:21

标签: asp.net asp.net-mvc-4 asp.net-web-api

我是MVC Web API的新手。如果问的话非常愚蠢,请原谅我。

我知道它的基本问题,但我无法找到我要去的错误。

这是我的sqlserver db:

enter code here

这是我的用户模型:

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web

Namespace WebApi.Models
    Public Class users
        Public Property userid() As Guid
        Public Property logintype() As String
        Public Property username() As String
        Public Property password() As String
        Public Property email() As String
        Public Property createddate() As DateTime

    End Class
End Namespace

现在这是我的usercontroller:

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Net
Imports System.Net.Http
Imports System.Web.Http
Imports MvcApplication1.WebApi.Models

Namespace WebApi.Controllers
    Public Class usercontroller
        Inherits ApiController
        Private Shared ReadOnly repository As New userdetails()
        Public Function GetAllUsers() As IEnumerable(Of users)
            Return repository.GetAll()
        End Function
    End Class
End Namespace

这是我的userdetails模型:

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Data
Imports System.Data.SqlClient

Namespace WebApi.Models
    Public Class userdetails
        Private users As New List(Of users)()
        Private con As SqlConnection
        Private da As SqlDataAdapter
        Private ds As New DataSet()

        Public Function GetAll() As IEnumerable(Of users)
            con = New SqlConnection("Data Source=.\sqlexpress;Initial Catalog=UsersList;Persist Security Info=True;User ID=sa;Password="****")
            da = New SqlDataAdapter("select * from users", con)
            da.Fill(ds)
            For Each dr As DataRow In ds.Tables(0).Rows
                users.Add(New users() With {.userid = Guid.Parse(dr(0).ToString()), .logintype = Integer.Parse(dr(1).ToString()), .username = dr(2).ToString(), .password = dr(3).ToString(), .email = Integer.Parse(dr(4).ToString()), .createddate = DateTime.Parse(dr(5).ToString())})
            Next dr
            Return users
        End Function
    End Class
End Namespace

这是我得到的错误:

enter image description here

1 个答案:

答案 0 :(得分:1)

以下是错误的 -

06-27 16:05:37.060: E/DatabaseUtils(2346): Writing exception to parcel
06-27 16:05:37.060: E/DatabaseUtils(2346): java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
06-27 16:05:37.060: E/DatabaseUtils(2346):  at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
06-27 16:05:37.060: E/DatabaseUtils(2346):  at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
06-27 16:05:37.060: E/DatabaseUtils(2346):  at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
06-27 16:05:37.060: E/DatabaseUtils(2346):  at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
06-27 16:05:37.060: E/DatabaseUtils(2346):  at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
06-27 16:05:37.060: E/DatabaseUtils(2346):  at android.os.Binder.execTransact(Binder.java:388)
06-27 16:05:37.060: E/DatabaseUtils(2346):  at dalvik.system.NativeStart.run(Native Method)

它们在模型中定义为.email = Integer.Parse(dr(4).ToString()) .logintype = Integer.Parse(dr(1).ToString()) ,然后为什么要将强制转换为string。所以删除类型转换并让它如下所示 -

Integer