Context does not load database data

Asked

Viewed 1,066 times

0

My context is not bringing the database data.

Error messages.

Value cannot be null.

"Value cannot be null. r nName of parameter: Connection"

Value cannot be null. Name of parameter: Connection

Cód conection string Business Entity

<connectionStrings>
<add name="ASCSEntities" connectionString="" providerName="System.Data.EntityClient" />

Cód conection string WPF

  <connectionStrings>
<add name="ASCSEntities" connectionString="" providerName="System.Data.EntityClient" />

Creation of Context:

 public partial class ASCSEntities : DbContext
{
    public ASCSEntities()
        : base("name=ASCSEntities")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }
}
  • 2

    Looking at the pictures you can perfectly see the error... Put the code of your conection string, to see if at least it is possible to help in something...

  • 1

    Hello. Do not insert images, enter code or error description. When to swap I remove the -1.

  • Note: The connection string I am passing dynamically.

  • 1

    @Jhonas would be a good idea, at the entrance of the method that will create the context, check the connection string. Investigate the method you are calling the method where the exception occurs.

  • I check the connection every time I log in, so much so that if the connection is in error I am forwarded to a configuration screen.

  • 1

    @Jhonas I think we need more context. Put the code that creates the context and the code that calls the method that creates the context for example. When I said check, I meant check if it’s not null, empty or blank.

  • I’m finding this very strange, had already happened not to load the context and then come back, now returned to load without me finding what really caused this failure.. It’s all working right now, but I still don’t know what caused it!

  • Could it be some configuration? I didn’t change practically anything and now it’s not loading the context again, I changed a store Previous, could it be something related to updates?

Show 3 more comments

2 answers

1


Can be double quotes in this snippet provider connection string=&quot; and in this App=EntityFramework&quot;. Switch to single quotes.

connectionString="metadata=res://*/ASCSEF.csdl|res://*/ASCSEF.ssdl|res://*/ASCSEF.msl;provider=System.Data.SqlClient;
     provider connection string='data source=10.000.000.00;initial catalog=ASCS;user id=XX;password=xxxxxx;MultipleActiveResultSets=True;App=EntityFramework'"
  • As I am passing my string conection dynamically I removed this Cód from the app.config, both in the business layer and in the WPF was like this: <add name="Ascsentities" connectionString=""providerName="System.Data.Entityclient" />

  • 1

    Still not working? And the WPF Provider is not "System.Data.Sqlclient"?

  • It still didn’t work. I believe that Provider is System.Data.Entityclient itself, I changed to make sure but gave errors in context creation.

  • tries to put different names in the links @Jhonas

1

You should put Connectionstring in both the WPF and your Business Entity, when you compile, the . config which predominates is the last layer of the application which is probably the WPF.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.