Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8098107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:58:38+00:00 2026-06-05T21:58:38+00:00

The error I am getting is Cannot open database NerdlyDB requested by the login.

  • 0

The error I am getting is “Cannot open database “NerdlyDB” requested by the login. The login failed.
Login failed for user ‘ComputerName\User Name’.

This is my connection string:

<add name="NerdlyDB" connectionString="Data Source=(LocalDb)\v11.0; Integrated Security=SSPI; initial catalog= NerdlyDB" providerName="System.Data.SqlClient"/>

This database was generates by using EF code first approach. I am new to this one, so I will show you what I did in case it is off somewhere:

On of my Entity Classes:

namespace NerdlyThings.Models
{
public class Post
{
    public int ID { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public string Content { get; set; }
    public DateTime Date { get; set; }
    public string Tags { get; set; }
}
}

DBContext Class

namespace NerdlyThings.Models
{
public class NerdlyDB : DbContext
{
    public DbSet<Post> Posts { get; set; }
    public DbSet<Comment> Comments { get; set; }
    public DbSet<Image> Images { get; set; }
    public DbSet<Quote> Quotes { get; set; }
}
}

I see that the error is obvious an authentication issue, but I don’t know where to set it using code first, only via setting up a db in sql server management studio.

*EDIT***

Ok, so I am not by the computer I originally did this on, but I had some time to kill at work so gave this another go by following the simple instructions here

I did this in Visual Studio 2012 RC in an MVC4 internet application template. Works like a dream and I can only assume I have either some strange configuration issue on my other computer, or something got messed up along the way. Anyway here is what I did:

Classes:

namespace CodeFirstBlog.Models
{
public class Blog
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string BloggerName { get; set; }
    public virtual ICollection<Post> Posts { get; set; }
}

public class Post
{
    public int Id { get; set; }
    public string Title { get; set; }
    public DateTime DateCreated { get; set; }
    public string Content { get; set; }
    public int BlogId { get; set; }
    public ICollection<Comment> Comments { get; set; }
}

public class Comment
{
    public int Id { get; set; }
    public DateTime DateCreated { get; set; }
    public string Content { get; set; }
    public int PostId { get; set; }
    public Post Post { get; set; }
}
}

DBContext Class:

namespace CodeFirstBlog.Models
{
public class BlogContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }
    public DbSet<Post> Posts { get; set; }
    public DbSet<Comment> Comments { get; set; }
}
}

I set these up and then created a controller like so (Just had it generated my selecting my context and the class):

public class BlogController : Controller
{
    private BlogContext db = new BlogContext();

    //
    // GET: /Blog/

    public ActionResult Index()
    {
        return View(db.Blogs.ToList());
    }

    //
    // GET: /Blog/Details/5

    public ActionResult Details(int id = 0)
    {
        Blog blog = db.Blogs.Find(id);
        if (blog == null)
        {
            return HttpNotFound();
        }
        return View(blog);
    }

    //
    // GET: /Blog/Create

    public ActionResult Create()
    {
        return View();
    }

    //
    // POST: /Blog/Create

    [HttpPost]
    public ActionResult Create(Blog blog)
    {
        if (ModelState.IsValid)
        {
            db.Blogs.Add(blog);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        return View(blog);
    }

    //
    // GET: /Blog/Edit/5

    public ActionResult Edit(int id = 0)
    {
        Blog blog = db.Blogs.Find(id);
        if (blog == null)
        {
            return HttpNotFound();
        }
        return View(blog);
    }

    //
    // POST: /Blog/Edit/5

    [HttpPost]
    public ActionResult Edit(Blog blog)
    {
        if (ModelState.IsValid)
        {
            db.Entry(blog).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(blog);
    }

    //
    // GET: /Blog/Delete/5

    public ActionResult Delete(int id = 0)
    {
        Blog blog = db.Blogs.Find(id);
        if (blog == null)
        {
            return HttpNotFound();
        }
        return View(blog);
    }

    //
    // POST: /Blog/Delete/5

    [HttpPost, ActionName("Delete")]
    public ActionResult DeleteConfirmed(int id)
    {
        Blog blog = db.Blogs.Find(id);
        db.Blogs.Remove(blog);
        db.SaveChanges();
        return RedirectToAction("Index");
    }

    protected override void Dispose(bool disposing)
    {
        db.Dispose();
        base.Dispose(disposing);
    }
}

Then I simply ran the application, used the generated views to create a new Blog. Works great. The database was generated in my App_Data folder, I can access it fine and see the generated schema. So problem solved, maybe? From this point I can use your suggested answers to tweak db settings and whatnot, so thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:58:40+00:00Added an answer on June 5, 2026 at 9:58 pm

    The best approach I have found so far is to create my own IDatabaseInitializer to run commands that I need to create indices and create users.

    public class MyContext : DbContext
    {
        static private Initializer DbInitializer;
        static MyContext()
        {
            DbInitializer = new MyContext.Initializer();
            Database.SetInitializer<MyContext>(DbInitializer);
        }
    }
    public class Initializer : IDatabaseInitializer<MyContext>
    {
        public void InitializeDatabase(MyContext context)
        {
            string ddl = "(Some SQL command to e.g. create an index or create a user)";
            context.Database.ExecuteSqlCommand(ddl);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert integer data to string , but I'm getting error cannot
On the query below I keep getting this error: Cannot read the next data
The complete error I am getting is this: Model compatibility cannot be checked because
I am getting the error Cannot add task ':webserver:build' as a task with that
I am getting the error Cannot resolve TargetName grdGeneral . What I am trying
I am getting a Cannot Find Symbol error for rowData, and columnLabels. Is the
I am getting an error in JSP and I cannot figure out what is
I'm getting the error: Uncaught TypeError: Cannot read property 'constructor' of undefined When declaring
I am getting the error A field initializer cannot reference the nonstatic field, While
I am getting the error: android.os.Build.VERSION cannot be resolved to a variable as an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.