0

I am developing a small MVC 5 application.

I made it, and deploy it on at this address: myMvcApp This app has a database behind and when I run it from my developing computer is running like expected. After deployment, when I run it on the server (link above) is going to Home/Index, and when I want to login, I insert the user and password and I get the following error:

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)

From this error, I understand that something is wrong with the connection string, I checked for several times and did not find something wrong.

The database is on my SmarterAsp.Net account, the connection string provided by SmarterAsp is:

"Data Source=SQL5007.Smarterasp.net;Initial Catalog=DB_9BCCA5_TargJoburi;User Id=DB_9BCCA5_TargJoburi_admin;Password=YOUR_DB_PASSWORD;"

I used CodeFirst to create my database and the connectionstring from web.config is:

  <connectionStrings>
    <add name="ApplicationDbContext" connectionString="Data Source=SQL5007.Smarterasp.net;Persist Security Info=True;User ID=DB_9BCCA5_TargJoburi_admin;Password=*********" providerName="System.Data.SqlClient" />
  </connectionStrings>

In order for you to get this error please use the following: user= test@test.com password= 123456

I don't know why is running ok on my computer with the connection string which I have and on the server is saying that the connection string is not ok. I am not enough experience to understand what to do now, this is why I ask for your help.

this is my DbContext class:

using System.Data.Entity;
using Microsoft.AspNet.Identity.EntityFramework;

namespace WebSite.Models
{
    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("ApplicationDbContext")
        {
        }

        public virtual DbSet<LocDeMunca> LocuriDeMunca { get; set; }
        public virtual DbSet<Judet> Judete { get; set; }
        public virtual DbSet<Oras> Orase { get; set; }
        public virtual DbSet<Company> Companies { get; set; }
        public virtual DbSet<DeInteres> JobDeInteres { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<LocDeMunca>()
                .HasRequired(j=>j.Judet)
                .WithMany(d=>d.LocuriDeMunca)
                .HasForeignKey(f=>f.JudetId)
                .WillCascadeOnDelete(false);
            modelBuilder.Entity<LocDeMunca>()
                .HasRequired(j => j.Oras)
                .WithMany(d => d.LocuriDeMunca)
                .HasForeignKey(f => f.OrasId)
                .WillCascadeOnDelete(false);
            modelBuilder.Entity<LocDeMunca>()
                .HasRequired(j => j.Company)
                .WithMany(d => d.LocuriDeMunca)
                .HasForeignKey(f => f.CompanyId)
                .WillCascadeOnDelete(false);
            modelBuilder.Entity<Oras>()
              .HasRequired(j => j.Judet)
              .WithMany(d => d.Orase)
              .HasForeignKey(f => f.JudetId)
              .WillCascadeOnDelete(false);

            modelBuilder.Entity<DeInteres>()
                .HasRequired(j => j.LocDeMunca)
                .WithMany()
                .HasForeignKey(f => f.LocDeMuncaId)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<DeInteres>()
                 .HasRequired(j => j.User)
                 .WithMany()
                 .HasForeignKey(f => f.UserId)
                 .WillCascadeOnDelete(false);


            base.OnModelCreating(modelBuilder);
        }


        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }
}

Can you give me some advice? what to change or check?

if you need mode info please ask.

Lucian Bumb
  • 2,821
  • 5
  • 26
  • 39
  • Have you ever check these 7 steps first? http://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci – Soner Gönül Nov 25 '15 at 14:05
  • The database is on SmarterAsp.Net and have no options there. I made test project to check the database (with model first) and is working, but with code first is not working – Lucian Bumb Nov 25 '15 at 14:09

0 Answers0