I face this problem when I store my data in Microsoft Azure Cloud.

here error log:

Server Error in '/' Application. 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) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: 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)

This is my code:

protected void Button1_Click(object sender, EventArgs e)
{
    int userId = 0;

    SqlConnection con = new SqlConnection("Data Source=asimo.database.windows.net;Initial Catalog=asimo;Persist Security Info=True;User ID=veeraiyan;Password=***********");
    con.Open();
    SqlCommand cmd = new SqlCommand("insert into registration(username,password,email)values('" + txtusername.Text + "','" + txtpassword.Text + "','" + txtemail.Text + "')", con);
    cmd.Parameters.AddWithValue("@username", txtusername.Text.Trim());
    cmd.Parameters.AddWithValue("@password", txtpassword.Text.Trim());
    cmd.Parameters.AddWithValue("@email", txtemail.Text.Trim());
    userId = cmd.ExecuteNonQuery();
    con.Close();

    string message = string.Empty;
    switch (userId)
    {
        case -1:
            message = "Username already exists.\\nPlease choose a different username.";
            break;
        case -2:
            message = "Supplied email address has already been used.";
            break;
        default:
            message = "Registration successful.\\nUser Id: " + userId.ToString();
            break;
    }
    ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
}

Related posts

Recent Viewed