I was trying to connect database to my ASP.NET website and encountered this error:
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
Additional information: Cannot open database "airplane_reservation" requested by the login. The login failed.
Login failed for user 'PELim\PeiErn'.
I create the database in SQL Management Studio 2014. I am using Visual Studio Coommunity 2015, this is my C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class CompleteOrder : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Random rnd = new Random();
int ordernum = rnd.Next(3, 10000);
string Name = Request.QueryString["name"];
string IC = Request.QueryString["ic"];
string Contact = Request.QueryString["contact"];
string Date = Request.QueryString["date"];
string Seats = (string) (Session["seats"]);
Label7.Text = Convert.ToString(ordernum);
Label4.Text = Name;
Label8.Text = IC;
Label10.Text = Contact;
Label12.Text = Date;
Label14.Text = Seats;
SqlConnection con = new SqlConnection(@"Data Source=PELim;Initial Catalog=airplane_reservation;Integrated Security=True;Pooling=False");
con.Open();
SqlCommand cmd =new SqlCommand("INSERT INTO Airplane_Reservation(Order_Number,Name,Identification_Number, Contact_Number, Departure_Date, Seats)VALUES('" + ordernum + "','" + Name + "','" + IC + "','" + Contact + "', '" + Date + "', '" + Seats + "')", con);
cmd.ExecuteNonQuery();
con.Close();
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("Main.aspx");
}
}
Please help me, thank you.