Sql-server – ASP.NET MVC incorrect connection string when connecting to mssql server

asp.net-mvcsql serverwindows-server-2008-r2

I built my website on ASP.NET MVC4 using mssql database, I deployed it on my local IIS 7 server and it works fine, but when I do to the exactly the same thing on virtual server hostgator.com it throws me this erro.

And tried 1000 connections strings and still no success.

It is strange because I did the same exact prodecure ion my local machine but it still can't connect to server.

I'm working on this problem last 24 hours and I can not find the solution for this problem.

I've contacted technical support and they said it's out of their support scope adn they can not help me with this.

I've done everything for this error to disapear because I had the same error on my local machine but when I configured it properly it worked, not so much on virtual server.

  • Firewall is off
  • remote aconnection are enabled in sql configuration
  • application pool is set to network service
  • I've added network service as new login in managgement studio with
    access to database

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)

Best Answer

So basically problem wasn't in connection string inside web.config ,it was entity framework's problem.

We started to develop our project on localhost and when finished we deployed site on hostgator.com, problem was, entityframework controlled all conection strings, therefore it was useless to change anything at all in web.config.

Here is address where we found solution: http://msdn.microsoft.com/en-us/library/bb739017.aspx

Here is the solution:

    namespace Finance.Models
    {
        // This constructor is the solution
        public class FinanceDataContext : DbContext
        {
            public FinanceDataContext()
            {
                this.Database.Connection.ConnectionString = "Data Source=servername;Initial Catalog=databasename;User ID=sql_username;Password=**********";
            }

            public DbSet<Administrator> Administrators { get; set; }
            public DbSet<News> News { get; set; }
            public DbSet<User> Users { get; set; }
            public DbSet<Plan> Plans { get; set; }
            public DbSet<Withdraw> Withdraws { get; set; }
        }
    }

There was no information about this, we on pure luck stumbled upon some error in entity framework and after 30 mins got the idea that entity framework is controlling the connection to database.

I am 100% sure someone will have the same problem, so if you can edit this question so it could been seen to everyone.