Error while connecting page with SQL Server

-2

I am trying to connect an ASP.NET page with a SQL Server database, but I get this error:

System.Data.SqlClient.SqlException
HResult=0x80131904
Message=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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Source=.Net SqlClient Data Provider

Code:

protected void Page_Load(object sender, EventArgs e)
{
    cn.ConnectionString = "Data Source=LAPTOP-QLEMTAEI/SQLEXPRESS;Initial Catalog=Lookatme;Integrated Security=True";
    cmd.Connection = cn;

    cn.Open();
}

protected void Button1_Click(object sender, EventArgs e)
{
    cmd.CommandText = "select * from Login where username='" + TextBox1.Text + "'and password='" + TextBox2.Text + "'";
    rd = cmd.ExecuteReader();

    if (rd.Read())
    {
        Response.Redirect("~/Index.aspx");
    }
    else
    {
        Response.Write("Error");
    }
}
c#
asp.net
sql-server
asked on Stack Overflow Jun 24, 2019 by Harpreet Singh • edited Jun 24, 2019 by marc_s

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0