发布的Azure移动服务不工作 [英] Publishing Azure Mobile Service doesn't work

查看:254
本文介绍了发布的Azure移动服务不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的Azure移动服务,完美的作品在本地,并使用招已经被彻底的测试。我设置参考值处理,以避免自参考循环

WebApiConfig.cs

 公共静态类WebApiConfig
{
    公共静态无效的注册()
    {
        //使用这个类来设置的配置选项为您的移动服务
        ConfigOptions选项=新ConfigOptions();        //使用这个类来设置的W​​ebAPI的配置选项
        HttpConfiguration配置= ServiceConfig.Initialize(新ConfigBuilder(选项));        JsonConvert.DefaultSettings =()=>新JsonSerializerSettings
        {
            格式化= Newtonsoft.Json.Formatting.Indented,
            ReferenceLoopHandling = ReferenceLoopHandling.Ignore
        };        config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
        //发展过程中显示在浏览器中的错误,取消以下
        //线。当您部署在生产中使用的服务再评论吧。
        // config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;        Database.SetInitializer(新MobileServiceInitializer());
    }

我的背景是pretty简单

 公共类SAServiceContext:的DbContext
{
    私人常量字符串的connectionStringName =NAME = MS_TableConnectionString;    公共SAServiceContext()
        :基地(的connectionStringName)
    {
    }    公共DbSet<&配方GT;食谱{搞定;组; }
    公共DbSet<方法>方法{搞定;组; }
    公共DbSet< RecipeItem>项目{搞定;组; }
    公共DbSet< D​​ietType> DietTypes {搞定;组; } ...     保护覆盖无效OnModelCreating(DbModelBuilder模型构建器)
    {
        串模式= ServiceSettingsDictionary.GetSchemaName();
        如果(!string.IsNullOrEmpty(模式))
        {
            modelBuilder.HasDefaultSchema(模式);
        }        modelBuilder.Conventions.Add(
            新AttributeToColumnAnnotationConvention< TableColumnAttribute,串>(
                ServiceTableColumn(属性,属性)=> 。attributes.Single()ColumnType.ToString()));
     }
  }

正如我所说的这一切都在本地工作完美,当我服务发布到云中,我可以看到的是MS_TableConnectionString确定,但该服务无法正常工作。它启动时确定,我可以看到从我的TableControllers所有的相关方法,但只要我点击一项(如GETSeason)我得到的一般错误

 在使用格式化'JsonMediaTypeFormatter生成的媒体类型应用/ JSON的样本已发生异常。异常消息:发生一个或多个错误。

我曾尝试

  preserveReferencesHandling = preserveReferencesHandling.Objects

但无济于事。
还指出的是,未在SQL天青被创建的表,因为它从未得到从WebApiConfig称为数据库Initilaizer方法。
在MS Azure的门户网站日志显示的arent任何错误,无论是。
 林卡住任何帮助AP preciated

修改
现在看到了Azure的门户下面的错误。 MS_TableConnectionString是天青所以不知道为什么它的说法那是一个问题,创建汽车。在当地我只是用的connectionString在web.config中


  

例外= System.InvalidOperationException:数据库初始化失败。无法初始化模式smallacorns_v3一个或多个对象。请确保数据库连接字符串是否正确。有关错误的更多详细信息,请参阅内部异常。 ---> System.InvalidOperationException:数据库初始化失败。无法初始化模式smallacorns_v3一个或多个对象。请确保数据库连接字符串是否正确。有关错误的更多详细信息,请参阅内部异常。 ---> System.Data.SqlClient.SqlException:用户没有执行此操作的权限。



解决方案

这看起来像使用的要连接到SQL Azure的数据库没有权限来创建SQL Azure的数据库的用户。

先给数据库用户,的db_owner 的角色和这个错误应该走了。

I have an Azure Mobile Service that works perfectly locally and has been thoroughly tested using Fiddler. I setup Reference Handling to avoid self referencing loops

WebApiConfig.cs

public static class WebApiConfig
{
    public static void Register()
    {
        // Use this class to set configuration options for your mobile service
        ConfigOptions options = new ConfigOptions();

        // Use this class to set WebAPI configuration options
        HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));

        JsonConvert.DefaultSettings = () => new JsonSerializerSettings
        {
            Formatting = Newtonsoft.Json.Formatting.Indented,
            ReferenceLoopHandling = ReferenceLoopHandling.Ignore                
        };

        config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;


        // To display errors in the browser during development, uncomment the following
        // line. Comment it out again when you deploy your service for production use.
        // config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

        Database.SetInitializer(new MobileServiceInitializer());
    }

My context is pretty simple

public class SAServiceContext : DbContext
{        
    private const string connectionStringName = "Name=MS_TableConnectionString";

    public SAServiceContext()
        : base(connectionStringName)
    {
    }

    public DbSet<Recipe> Recipes { get; set; }
    public DbSet<Method> Methods { get; set; }
    public DbSet<RecipeItem> Items { get; set; }
    public DbSet<DietType> DietTypes { get; set; }...

     protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        string schema = ServiceSettingsDictionary.GetSchemaName();
        if (!string.IsNullOrEmpty(schema))
        {
            modelBuilder.HasDefaultSchema(schema);
        }

        modelBuilder.Conventions.Add(
            new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>(
                "ServiceTableColumn", (property, attributes) =>               attributes.Single().ColumnType.ToString()));
     }
  }

As I said this all works perfectly locally and when I publish the service to the cloud I can see the MS_TableConnectionString is ok but the service does not work. It starts up ok and I can see all the relevant methods from my TableControllers but as soon as I click one (eg GETSeason) I get the generic error

An exception has occurred while using the formatter 'JsonMediaTypeFormatter' to generate sample for media type 'application/json'. Exception message: One or more errors occurred.

I have tried

PreserveReferencesHandling = PreserveReferencesHandling.Objects

but to no avail. Also noted is that the tables are not being created in SQL Azure as it never gets to the Database Initilaizer method called from WebApiConfig. The logs in MS Azure portal arent showing any errors either. Im stuck any help appreciated

EDIT Now seeing the following error in Azure portal. MS_TableConnectionString is auto created in Azure so not sure why its saying thats a problem. Locally I just use connectionString in web.config

Exception=System.InvalidOperationException: Database initialization failed. Could not initialize one or more objects in schema 'smallacorns_v3'. Please ensure that the database connection string is correct. For more details on the error, please see the inner exception. ---> System.InvalidOperationException: Database initialization failed. Could not initialize one or more objects in schema 'smallacorns_v3'. Please ensure that the database connection string is correct. For more details on the error, please see the inner exception. ---> System.Data.SqlClient.SqlException: User does not have permission to perform this action.

解决方案

This looks like the user using which you are connecting to the Azure SQL Database doesn't have permissions to create the Azure SQL database.

Try giving the database user, 'db_owner' role and this error should go away.

这篇关于发布的Azure移动服务不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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