gpt4 book ai didi

asp.net-mvc - Azure 数据库出现错误:参数 'nameOrConnectionString' 不能为 null、为空或仅包含空格

转载 作者:行者123 更新时间:2023-12-01 23:20:14 25 4
gpt4 key购买 nike

我的数据库和其他存储位于 azure 的云存储上。我正在使用实体代码优先应用程序,但问题是当我尝试使用CloudConfigurationManager.GetSetting()从云存储读取连接字符串时我收到以下错误:

错误:参数“nameOrConnectionString”不能为 null、为空或仅包含空格。EntityFramework.dll 中发生“System.ArgumentException”类型的异常,但未在用户代码中处理

这是我的 Azure 项目:Demo.Web.Azure

它有2个配置文件:

1)ServiceConfiguration.Cloud.cscfg:

<Role name="Demo.Web">
<Setting name="MyConnectionString"
value="Server=----;Database=DemoEntity;User ID=---;Password=---&amp;w;Trusted_Connection=False;
Encrypt=True;MultipleActiveResultSets=True;" />

<Setting name="Demo.Storage"
value="DefaultEndpointsProtocol=https;AccountName=---;AccountKey=------"
/>

2)ServiceConfiguration.Local.cscfg:

<Role name="Demo.Worker">
<Setting name="Demo.Storage"
value="DefaultEndpointsProtocol=https;AccountName=---;AccountKey=------"
/>

3)ServiceDefinition.csdef:

<ServiceDefinition name="Demo.Web.Azure" schemaVersion="2014-06.2.4">
<WebRole name="RepuGuard.Web" vmsize="Small">
<ConfigurationSettings>
<Setting name="MyConnectionString" />

<Setting name="Demo.Storage" />
</ConfigurationSettings>

</WebRole>

<WorkerRole name="Demo.Worker" vmsize="Small">
<ConfigurationSettings>
<Setting name="MyConnectionString" />

<Setting name="Demo.Storage" />
</ConfigurationSettings>

</WorkerRole>

</ServiceDefinition>

这是我的上下文文件,其中读取数据库连接字符串:

public partial class MyDemoDBContext : DbContext, IDisposable
{
public ObjectContext Context { get; set; }
public MyDemoDBContext()
: base(CloudConfigurationManager.GetSetting("MyConnectionString"))//Getting Error here
{
Context = ((IObjectContextAdapter)this).ObjectContext;
}
public MyDemoDBContext (string connectionString)

: base(connectionString)

{

Context = ((IObjectContextAdapter)this).ObjectContext;

}
}

这里出现错误:

public MyDemoDBContext()
: base(CloudConfigurationManager.GetSetting("MyConnectionString"))
{
Context = ((IObjectContextAdapter)this).ObjectContext;
}

最佳答案

如果您有多个项目正在解决,请尝试设置启动项目将解决此问题。(抱歉延迟)

关于asp.net-mvc - Azure 数据库出现错误:参数 'nameOrConnectionString' 不能为 null、为空或仅包含空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30047055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com