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 6698089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:32:11+00:00 2026-05-26T06:32:11+00:00

I’ve followed a tutorial in MVC 3, and done this: Made 4 classes and

  • 0

I’ve followed a tutorial in MVC 3, and done this:

Made 4 classes and a DBClass:
User [has a] List of Websites [has a] List of Pages [has a] List of Comments [each marked word is a class of its own].

Then, I made a class called UserDataBaseDB this way:

public partial class UserDataBaseDB : DbContext
    {
        public DbSet<User> Users { get; set; }

        public UserDataBaseDB()
            : base(@"UserDataBaseDB")
        {
            if (this.Database.Exists())
            {
                try
                {
                    this.Database.CompatibleWithModel(false);
                }
                catch (InvalidOperationException)
                {
                    this.Database.Delete();
                }
            }

            if (!this.Database.Exists())
            {
                this.Database.Create();
                Seed();
            }
        }

        private void Seed()
        {
            var Mark = new User();
            Mark.ID = 0;
            Mark.MD5Pass = "4297f44b13955235245b2497399d7a93";
            Mark.UserName = "Admin";

            var Troll = new Comment();
            Troll.CommentData = "Fake!";
            Troll.Writer = Mark;

            var Site = new Website();
            Site.Name = "Admin Site";

            Site.Pages.ElementAt(0).Data = "Awesome website!";
            Site.Pages.ElementAt(0).Comments.Add(Troll);

            Mark.Websites.Add(Site);

            Users.Add(Mark);
        }
        public static UserDataBaseDB Create()
        {
            return new UserDataBaseDB();
        }
        public User FindUserByID(int id)
        {
            return (from item in this.Users
                    where item.ID == id
                    select item).SingleOrDefault();
        }

Then I added the Controller and View, and navigated to http://localhost:40636/Main, and I saw this message:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified)

Line 14:             : base(@"UserDataBaseDB")
Line 15:         {
Line 16:             **if (this.Database.Exists())**
Line 17:             {
Line 18:                 try

Letting the marked line be the red line.

I’ve tried to re-install Entity Framework, also trying EFCodeFirst, tried making my own SqlDataBase and giving it the connection string, but nothing worked.

Does anyone know what’s the solution? Thank you!

PS: I’m using VS Ultimate SP1 on a Win7 64bit machine.

  • 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-05-26T06:32:11+00:00Added an answer on May 26, 2026 at 6:32 am

    This is likely a connect string issue, however I do see that you are trying to seed information and fully use the context in the constructor, which I would highly recommend you dont do.
    You can implement the OnModelCreating method and attempt your initialization code there, or even better in your application start. It just doesnt seem right to be stuck in the constructor as initialization is just starting at this point.

    Set a breakpoint on

     if (this.Database.Exists())
    
    

    Does the error happen immediately after that line? If so, triple check your connect string. Do you have your code in one project, or broken out? Make sure you are checking the connect string in your root web project’s web.config and not any component’s app.config if you so happen to be using that design.

    Each time you changes from code-first, etc did you change your connect string? A code-first connect string is named after your context class and is simple:

    
    <add name="UserDataBaseDB" connectionString="Data Source=|DataDirectory|test.sdf" providerName="System.Data.SqlServerCe.4.0" /%gt;
    
    

    That is of course using SQLCe4. Sql Server would be

    
    <add name="UserDataBaseDB" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=YourDbName;Integrated Security=True;Pooling=False" /%gt;
    
    

    or for a db in app_Data

    
    <add name="UserDataBaseDB" providerName="System.Data.SqlClient" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\YourDatabase.mdf;User Instance=true" /%gt;
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.