mrahhal / Migrator.EF6

.NET Core CLI tool to enable EF6 migrations in an Asp.Net Core app.
MIT License
82 stars 15 forks source link

The argument 'nameOrConnectionString' cannot be null, empty or contain only white space. #33

Closed jimbo74 closed 7 years ago

jimbo74 commented 7 years ago

When trying to add a new migration passing in a connection string I get the above error.

My command is similar to: dotnet ef migrations add TestClassAdded --connection-string "Server=xxx;Database=yyy;etc.."

The tool compiles my project and then states:

Using provided connection string as an override. The argument 'nameOrConnectionString' cannot be null, empty or contain only white space.

I have successfully done the initial create (with connection string hard coded) and the update database following this (passing in the connection string) but now I get this strange result when trying to add another migration where it tells me it's using the connectionstring but then doesn't

mrahhal commented 7 years ago

Is there a stacktrace with the error?

mrahhal commented 7 years ago

Ok so, we're looking at this piece of code:

if (_connectionString != null)
{
    Console.WriteLine("Using provided connection string as an override.");
    dbMigrationsConfiguration.TargetDatabase = new DbConnectionInfo(_connectionString, _providerName);
}

The only reason that error would happen is if the connection string is all whitespace. That's weird.

jimbo74 commented 7 years ago

This is a print of the command and error:

migrations error

mrahhal commented 7 years ago
jimbo74 commented 7 years ago

version 1.0.8

I get the same error with the other commands

mrahhal commented 7 years ago

Are you by any chance using localdb? Doesn't look like it, but now I remembered that in my tests localdb didn't work when you specify the connection string from the command line (so I used sqlexpress). Now, the error here is completely different anyway, it doesn't make much sense. The "_connectionString" variable is only every written to by the command line parser ("Microsoft.DotNet.Cli.Utils").

Would the same issue occur if you try with a fresh project (+ sqlexpress)? Because it's working fine on my machine (yeah I know).

jimbo74 commented 7 years ago

I'm using a database on azure, I can try a new project with sqlexpress but that isn't my end goal so I don't see what I'll get from that.

Thanks for your help with this though

mrahhal commented 7 years ago

Problem is I can't think of something that might lead to this error. If @DOTang would be so kind to give his input. Are you still using this option (specifying the connection string in the command line)? If so is it working okay for you?

jimbo74 commented 7 years ago

Yes I saw @DOTang was trying to do something similar which is what led me to this. Lets see what he says

DOTang commented 7 years ago

I use the connection string in the command, I use a normal SQL DB, not express or azure though.

mrahhal commented 7 years ago

Hmm maybe the problem is related to Azure? I'm seeing the same expected behavior on my end.

mrahhal commented 7 years ago

I'm closing this, please reopen if you still have issues.