내 ASP.NET 웹 사이트 데이터베이스에 연결을 시도하고이 오류가 발생 ASP.NET 웹 사이트에 대한 사용자 코드를 연결 데이터베이스에 의해 처리되지 않은했다 Visual Studio 커뮤니티 2015를 사용 중입니다.이 코드는 C# 코드입니다.SQL 예외
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");
}
}
감사합니다.
DB에서 사용자를 추가하는 시도하고 연결 문자열을 업데이트합니다. 그런데 web.config에서는 연결 문자열을 사용하고 코드에서는 직접 연결 문자열을 사용하지 마십시오. –
u는이 데이터베이스에 대한 사용자를 만들고 연결 문자열에서 변경한다는 의미입니까? @SanishJoseph –
예. 그것이 내가 의미했던 것입니다. 적절한 권한을 가진 역할을 부여하십시오. –