New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build-Solution.ps1 only works with .\SQLEXPRESS instance #221
Comments
Had a chance to get further info on this. The problem is because the connection string obtained in the Powershell script is not passed to the UpdateDatabase MSBuild task. Instead, the MigrationsContext class passes the string "NuGetGallery" to its base class constructor (line 51 in Settings.cs)
Because the build script doesn't have an associated configuration file (App.config or Web.config), then the connection string with name "NuGetGallery" can't be found, leaving Entity Framework to fall back to its default behaviour of using the .\SQLEXPRESS database instance (which doesn't exist on my machine). I'm not sure of any way to get a full connection string to Entity Framework using Code First. I tried a test by replacing the literal string "NuGetGallery" with the actual connection string of my database, but the error is then If anyone has any ideas how to progress this, I'd be glad to help out. |
@yeurch As soon as we get through the 1.6 release, I'll look into this. |
@anglicangeek Thanks Drew, I tried to play around a little more by passing a DbConnection to the DbContext constructor, instead of a string. To do this, I did the following:
Then, to test this approach, I replaced "NuGetGallery" with my actual Sql connection string, as detailed above. Still get the invalid key value exception. |
I think the issue lies in string connectionStringName = this.ConnectionStringName;
string connectionString = this.ConnectionString;
bool flag = string.IsNullOrWhiteSpace(connectionString);
string connectionProviderName = this.ConnectionProviderName;
bool flag2 = string.IsNullOrWhiteSpace(connectionProviderName);
if ((flag || flag2) || string.IsNullOrWhiteSpace(connectionStringName))
{
DbContextInfo info = new DbContextInfo(this.ContextType);
connectionStringName = info.ConnectionStringName;
if (flag)
{
connectionString = info.ConnectionString;
}
if (flag2)
{
connectionProviderName = info.ConnectionProviderName;
}
}
ConnectionStringSettingsCollection connectionStringSettings = new ConnectionStringSettingsCollection();
connectionStringSettings.Add(new ConnectionStringSettings(connectionStringName, connectionString, connectionProviderName));
return new DbContextInfo(this.ContextType, connectionStringSettings); By all rights, I think it is getting the literal string you're using, but it seems to be trying to add a connection string to a collection? Perhaps this is why the stack trace shows:
At any rate, this is super annoying because my local instance is not named SQLEXPRESS. |
Is there a known workaround in the mean time? |
I don't know, because I haven't looked at the problem yet. I can look at this today or tomorrow. |
Thanks - we are considering working with the project for in house package management and I wanted to give a demo. If I can assist let me know - I'm just familiarizing myself with the project. |
@odelljl Don't let this issue stop you from working with the project. The solution builds just fine inside Visual Studio and seems to work with no issues. We're using this for in house package management ourselves. |
Yep, like @yeurch said, please don't let this stop you from playing with the source. I've been dreadfully sick the last few days, but this is high on my list of things to look at. |
@yeurch Yes - thanks! - I just noticed it was EF Code First. Quick change of the connection string and I'm up and running. |
It looks like this will be fixed when we upgrade to EF 4.3. I can't do that just yet because I can't get MiniProfiler to work with it. In the mean-time, I think I'm going to just yank the update and revert scripts out, since EF 4.3 will have it's commands for this anyway, and there is a app_start update in there already, too. |
Thanks - that makes sense to me. |
Regardless of any changes made to the connection string in Website\Web.config, I've found that the Build-Solution.ps1 PowerShell script always tries to connect to the local SQLEXPRESS instance of SQL Server when running UpdateDatabase, causing a build failure if the instance doesn't exist.
Building and running the solution in Visual Studio works fine for me, and creates and initializes the database correctly.
The text was updated successfully, but these errors were encountered: