加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 获取错误参数’nameOrConnectionString’不能为n

发布时间:2020-12-16 07:11:00 所属栏目:asp.Net 来源:网络整理
导读:我在azure云存储上使用我的数据库和其他存储.我正在使用实体代码首次使用但问题是当我尝试使用CloudConfigurationManager.GetSetting()从云存储中读取连接字符串时,我收到以下错误: 错误:参数’nameOrConnectionString’不能为null,为空或仅包含空格. Enti
我在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>

这是我的Context文件,它读取数据库连接字符串:

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;
           }

解决方法

如果您有多个项目正在解决方案,尝试设置启动项目将解决此问题.(sry延迟)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读