Hi there.! I've been working on our Software Analysis Development project for how many days and sleepless nights, the application is an Online Shopping. I'm using Microsoft Visual Studio 2010 as my environment, then I used C# as language for the site. I used Microsoft SQL 2008 R2 as my server and I made Database on the SQL Sever Management Studio with the tables namely dbo.login, dbo.cart, dbo.userdetails, dbo.dresses.
When I log in as administrator on the Log In page (Log In.aspx), there is an error shown on the response and I can't continue with it. As well as when I run the other pages with similar codes, the same error was shown.
Here's the code for the Log In.aspx.cs, please do check, I really need you help.. Please...
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Log_In : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
int flag = 0;
SqlConnection con = new SqlConnection("Data Source=(localhost);Initial Catalog=chenezboutique;Integrated Security=true;"); // access database
SqlCommand com = new SqlCommand("select * from login", con); // access login table from the database
con.Open();
if (con.State == ConnectionState.Open)
{
SqlDataReader dtr; // check database for user's account
dtr = com.ExecuteReader();
while (dtr.Read())
{
if (dtr[0].ToString().Equals(TextBox1.Text) && dtr[1].ToString().Equals(TextBox2.Text))
{
flag = 1;
break;
}
}
if (flag == 1)
{
HttpCookie uname = new HttpCookie("username");
HttpCookie upass = new HttpCookie("userpass");
HttpCookie rights = new HttpCookie("rights");
uname.Value = TextBox1.Text;
upass.Value = TextBox2.Text;
rights.Value = dtr[2].ToString();
Response.Cookies.Add(uname);
Response.Cookies.Add(upass);
Response.Cookies.Add(rights);
Response.Redirect("Home.aspx");
}
}
con.Close();
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
}
}
Here's the error in Red:
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)
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Source Error:
Line 25: SqlConnection con = new SqlConnection("Data Source=(localhost);Initial Catalog=chenezboutique;Integrated Security=true;"); // access database
Line 26: SqlCommand com = new SqlCommand("select * from login", con); // access login table from the database
Line 27: con.Open();
Line 28: if (con.State == ConnectionState.Open)
Line 29: {