Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

SQL Server not reachable from ASP.NET application #1240


User avatar
0
jubeh created

I have an ASP.NET site hosted with [http://asphostportal.com]) , My ASP.NET page which has a small form to handle enrollment into his course.

Obviously the data from this form has to be inserted into a database.

My problem lies in the actual connection to the database server, I have it on my local PC, for testing purposes.

I can connect to the server just fine through my SQL Server Management Studio, however when I try to connect from my web application (uploaded it to a free host purely for testing), it gives me this 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: TCP Provider, error: 0 - An attempt was made to access a socket in a way forbidden by its access permissions.)

After extensive Google'ing and rewriting the connection string in my web.config file, I still can't find what's going wrong exactly.

I know for a fact that the DNS I'm using works, as a friend of mine has already tested it several days ago by connecting through his own SQL Server Management Studio.

Here's my web.config: (blanked out the password in the constring, obviously)

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
    <customErrors mode="Off"/>
  </system.web>
  <appSettings>
      <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>
  <connectionStrings>
     <add name="SQLCS" 
          providerName="System.Data.SqlClient"   
          connectionString="Server=ydekempe.ddns.net,5555\Cocktails;Database=Website;Integrated Security=False;User ID=WebUser;Password=********;"/>
  </connectionStrings>
</configuration>

And just for being complete in providing you everything you may need, here's the code for the actual connection:

protected void Inschrijven(object sender, EventArgs e)
{
    int uid = 0;
    string conStr = ConfigurationManager.ConnectionStrings["SQLCS"].ConnectionString;

    try
    {
        using (SqlConnection conn = new SqlConnection(conStr))
        {
            using (SqlCommand cmd = new SqlCommand("Inschrijven", conn))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter())
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@naam", txtNaam.Text.Trim());
                    cmd.Parameters.AddWithValue("@voornaam", txtVoorNaam.Text.Trim());
                    cmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim());
                    cmd.Connection = conn;
                    conn.Open();
                    uid = Convert.ToInt32(cmd.ExecuteScalar());
                    conn.Close();
                }
            }
        }
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }
    string msg = "";
    switch (uid)
    {
        case 0:
            msg = "Er ging iets mis.\\nProbeer later opnieuw";
            break;
        case -1:
            msg = "Dit e-mail adres is al in gebruik.";
            break;
        default:
            msg = "Inschrijving verwerkt.";
            break;
    }
    ClientScript.RegisterStartupScript(GetType(), "Boodschap", "Boodschap: '" + msg + "');", true);
}

PS: The actual connection info is IP: ydekempe.ddns.net & Port: 5555 Just in case you were wondering.


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    ABP uses "Default" connection string by default but you used "SQLCS". Can that be the problem?