Getting error Argument 'nameOrConnectionString' cannot be empty, empty, or contain only space with Azure Database

I have my database and other storage on azure cloud storage. I am using the first Entity Code app, but the problem is when I try to read the connection string from cloud storage using CloudConfigurationManager.GetSetting () I get below error:

Error: argument 'nameOrConnectionString' cannot be empty, empty, or contain only a 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 config files:

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 that reads the 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;
           }

      

+3


source to share


2 answers


If you have multiple projects within a solution, try setting up a startup project to resolve this issue. (sry for delay)



+6


source


A spelling mistake in appsettings.json

caused the same for me System.ArgumentException

. I found that the string "ConnectionStrings"

turned into "CondfSnectionStrings"

. I do not know why. My eye just obscured the problem until another programmer pointed it out to me.



0


source







All Articles