SqlDataReader dr;
String connectionstr = "Server=(local)/SQLEXPRESS;Database=db_Logininformation;User Id= jananni-PC/jananni;Password=;";
SqlConnection con = new SqlConnection(connectionstr);
con.Open();
com = new SqlCommand("select Password from userinformation where Username='" + TextBox1.Text + "'", con);
dr = com.ExecuteReader();
if (!dr.Read())
{
Response.Write("Invalid User");
}
else
{
if (dr[0].ToString() == TextBox2.Text)
{
Response.Redirect("~/mainPage.aspx");
}
else
{
Response.Write("Wrong Password");
TextBox2.Focus();
}
}
}
The error shown is :con.Open(); 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)
helpmee
0 Points
3 Posts
Sql Server 2008 connectivity error
Jan 25, 2013 01:15 AM|LINK
My question may be simple but i have the following error ocurred in my code when i try to debug.
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand com;
SqlDataReader dr;
String connectionstr = "Server=(local)/SQLEXPRESS;Database=db_Logininformation;User Id= jananni-PC/jananni;Password=;";
SqlConnection con = new SqlConnection(connectionstr);
con.Open();
com = new SqlCommand("select Password from userinformation where Username='" + TextBox1.Text + "'", con);
dr = com.ExecuteReader();
if (!dr.Read())
{
Response.Write("Invalid User");
}
else
{
if (dr[0].ToString() == TextBox2.Text)
{
Response.Redirect("~/mainPage.aspx");
}
else
{
Response.Write("Wrong Password");
TextBox2.Focus();
}
}
}
The error shown is :con.Open(); 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)
oned_gk
All-Star
30989 Points
6343 Posts
Re: Sql Server 2008 connectivity error
Jan 25, 2013 02:08 AM|LINK
Change (local) to dot