Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)

share|improve this question
    
The error message implies that your app can't connect at all to the SQL instance, as opposed to connecting and then failing for a bad login/password. Normally this means DNS, firewall, instance-down or SQL Browser problems. Are you saying that you can connect via SSMS? Is there an instance name? Can you post your connection string, with any sensitive/identifying info changed? Just to be sure, your production iis and sqlserver are both at hostgator and on the same box, right? –  darin strait Nov 5 '12 at 23:12
    
I will post solution as soon as possible because, lot of people will think why there MVC 4's aren't working. Stay put. –  skmasq Nov 6 '12 at 1:06
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.