4

I'm trying to connect to my existing database using an empty template project for ASP.NET and EF 7, beta 7. This is what my project.json looks like:

{
  "webroot": "wwwroot",
  "userSecretsId": "aspnet5-Titanes2015-409e9e37-b7bb-4185-b7aa-6dc336087524",
  "version": "1.0.0-*",

  "dependencies": {
    "EntityFramework.Commands": "7.0.0-beta7",
    "EntityFramework.SqlServer": "7.0.0-beta7",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Google": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta7",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta7",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta7",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta7",
    "Microsoft.AspNet.Mvc": "6.0.0-beta7",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta7",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta7",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta7",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta7",
    "Microsoft.Framework.Logging": "1.0.0-beta7",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta7",
    "Microsoft.Framework.Logging.Debug" : "1.0.0-beta7",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta7"
  },

  "commands": {
    "web": "Microsoft.AspNet.Hosting --config hosting.ini",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
  ],

  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],

  "Data": {
    "DefaultConnection": {
      "ConnectionString": "Server=192.168.XX.XXX\\devsql;Database=XXXXXXX;Trusted_Connection=True;user id=XXXXXX;password=XXXXXX;MultipleActiveResultSets=true"
    }
  },

  "EntityFramework": {
    "ApplicationDbContext": {
      "ConnectionStringKey": "Data:DefaultConnection:ConnectionString"
    }
  },

  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
  }
}

Now, I have looked all over Google and already checked the following questions:

Database-first EF7-beta7 dnx ef dbcontext scaffold command fails

Generating code from an existing database EF7

I have tried running all of the following commands, as mentioned in those posts:

dnx ef dbcontext scaffold "ConnectionString" EntityFramework.SqlServer
dnx . ef dbcontext scaffold "<connectionString>"
Scaffold-DbContext '<connectionString>'

Every single time I get the following error:

The term 'dnx' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again

What am I doing wrong?

Accessing my remote database from an empty template project should be a pretty straightforward process, but I've been fighting this for a while. Could anyone point me in the right direction?

Community
  • 1
  • 1
erictrigo
  • 989
  • 2
  • 13
  • 41
  • Try re-installing `dnvm`. – Henk Mollema Sep 25 '15 at 11:46
  • From the PowerShell window I ran: dnvm and noticed it said beta5. I ran dnvm update-self and it updated to beta8-15518, which is probably still not good since I'm using beta7 for everything else. Still, I can't get the commands above to work and get the same message when I try running dnx ef dbcontext scaffold "ConnectionString" EntityFramework.SqlServer. – erictrigo Sep 25 '15 at 11:52
  • DNVM beta 8 should be correct. It uses NuGet as stable feed so `dnvm upgrade` will get you beta7 bits for instance. Do you also get the same error when running `dnx web`? – Henk Mollema Sep 25 '15 at 11:58
  • I get "The term 'dnx' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again". So no matter what I add after "dnx", it will break. – erictrigo Sep 25 '15 at 12:02
  • Try removing the `.dnx\bin` folder from your user profile and install it again in an elevated prompt using [this](https://github.com/aspnet/Home#cmd). – Henk Mollema Sep 25 '15 at 12:09
  • I tried doing that and it reinstalled fine, but I still get the same issues. What I'm trying to run, from the PowerShell Interactive Window in VS, is: PS C:\Development\Project> dnx ef dbcontext scaffold "ConnectionString" EntityFramework.SqlServer – erictrigo Sep 25 '15 at 12:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/90616/discussion-between-eric-trigo-and-henk-mollema). – erictrigo Sep 25 '15 at 12:25

1 Answers1

3

While discussing in the chat, we figured out that removing the installed runtimes from C:\Users\<username>\.dnx\runtimes and re-installing the latest version with dnvm upgrade was the solution.

Tip: first check if dnvm is updated to the latest version. You can update it with dnvm update-self or completely re-install it by removing the content in the C:\Users\<username>\.dnx\bin folder and running this PowerShell script.

Henk Mollema
  • 44,194
  • 12
  • 93
  • 104
  • `dnvm list` and `dnvm use` are usually what I need to get things running. – Leonardo Herrera Sep 25 '15 at 17:31
  • I'm just curious, but on a related note -- has anyone stumbled on making dnvm and the related tools operate on a global runtime cache for a server? We have ADDS at my work, and use dnx on isolated projects. I know one can install to a Global runtime dir, but acquiring that instead of user account for all related tools seems insurmountable. – Nathan Teague Sep 28 '15 at 17:02