[英]Publishing Azure Mobile Service doesn't work
我有一个Azure移动服务,可以在本地完美运行,并且已经使用Fiddler进行了全面测试。 我设置了引用处理以避免自我引用循环
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());
}
我的情况很简单
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()));
}
}
正如我所说的,这一切在本地都可以正常运行,当我将服务发布到云中时,我可以看到MS_TableConnectionString可以,但是该服务无法正常工作。 它启动正常,我可以从TableControllers中看到所有相关方法,但是一旦单击其中一个(例如GETSeason),我就会得到一般错误
An exception has occurred while using the formatter 'JsonMediaTypeFormatter' to generate sample for media type 'application/json'. Exception message: One or more errors occurred.
我努力了
PreserveReferencesHandling = PreserveReferencesHandling.Objects
但无济于事。 还应注意的是,由于没有从WebApiConfig调用的Database Initilaizer方法,因此不会在SQL Azure中创建表。 MS Azure门户arent中的日志也显示任何错误。 我卡住任何帮助表示赞赏
编辑现在,在Azure门户中看到以下错误。 MS_TableConnectionString是在Azure中自动创建的,因此不确定为什么这样说是一个问题。 在本地我只是在web.config中使用connectionString
Exception = System.InvalidOperationException:数据库初始化失败。 无法初始化架构'smallacorns_v3'中的一个或多个对象。 请确保数据库连接字符串正确。 有关错误的更多详细信息,请参见内部异常。 ---> System.InvalidOperationException:数据库初始化失败。 无法初始化架构'smallacorns_v3'中的一个或多个对象。 请确保数据库连接字符串正确。 有关错误的更多详细信息,请参见内部异常。 ---> System.Data.SqlClient.SqlException:用户没有执行此操作的权限。
看起来您用来连接到Azure SQL数据库的用户没有创建Azure SQL数据库的权限。
尝试赋予数据库用户“ db_owner ”角色,该错误应消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.