Trouble Publishing an MVC4 site on HostGator

asp.net-mvcconnection-stringssql-server-2008

I have been working on a C# MVC4 website and trying to publish it to a Host Gator shared Windows hosting account. They are running both MSSQL 2008 and mySql. We have run into some trouble when trying to get the site to work.

First of all we are using the code first approach to database creation with MVC as well as implementing the SimpleMembership that it offers.

If I publish a basic MVC website as created by a Visual Studios 2010 template, the site will load and display pages, as long as it does not attempt to connect to a database.

I have worked with the Host Gator technical support but they are unable to give me a good answer on how to actually connect to the database. And I have tried all manner of conneciton strings, as well as trying to implement SqlServerCe 3.5.

Some of the connection string examples I have tried are as follows:

<configuration>
    <connectionStrings>
        <add connectionString="Server=myServerAddress;Database=myDataBase;ID=myUsername;Password=myPassword;Trusted_Connection=False" name="connectionName" providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

and this:

 <connectionStrings>
                <add connectionString=Data Source=ServerIPAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword; />
            </connectionStrings>
        </configuration>

But nothing seems to work, we end up with errors all over the place such as:

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)

It all points to connection strings and not being able to connect.

Does any one have any success stories with HostGator and MVC?

Best Answer

I'm guessing they don't provide RDP access. If so, first thing I would do is attempt to ping the sql server, and try to create a system DSN using odbcad32, and verify that the database is accessible independent of the application.

If your database is not the only or default instance on the SQL server, you may need to specify the instance name in the connection string:

server=serverName\instanceName

It's possible to further craft the connection string to specify tcp/ip and the SQL port number:

tcp:servernameorIP\instanceName,1433  

Another technique that may help provide more information is to perform some other tests in your global.asax.cs, independent of the database access that uses the connections tring, such as pinging the sql server, and attempting to establish a simple tcp connection to the SQL server on 1433.