遇到错误参数'nameOrConnectionString'不能为null,为空或Azure数据库仅包含空格 [英] Getting Error The argument 'nameOrConnectionString' cannot be null, empty or contain only white space with Azure Database

查看:873
本文介绍了遇到错误参数'nameOrConnectionString'不能为null,为空或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;
           }

解决方案

如果您有多个正在解决的项目,请尝试设置启动项目将解决此问题.

I am having my database and other storage on azure cloud storage.i am using Entity Code first appoach but problem is when i am trying to read connection string from cloud storage using CloudConfigurationManager.GetSetting() i am getting below error:

Error:The argument 'nameOrConnectionString' cannot be null, empty or contain only white space. An exception of type 'System.ArgumentException' occurred in EntityFramework.dll but was not handled in user code

This is my Azure project:Demo.Web.Azure

It has 2 configurations file:

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>

This is my Context file which read Database connection string:

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;

             }
}

Getting error here:

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

解决方案

If you have multiple projects under solution, try setting up the startup project will resolve this issue.(sry for the delay)

这篇关于遇到错误参数'nameOrConnectionString'不能为null,为空或Azure数据库仅包含空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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