|
|
|
ไม่สามารถ insert ลง database ได้ [MsSQLserver 2014] ใช้ hosting myasp.net |
|
|
|
|
|
|
|
Code (C#)
cn = new SqlConnection("Data Source = sql5026.myasp.net; Initial Catalog = DB_A18CFE_trevorw7; Persist Security Info = True; User ID = DB_A18CFE_trevorw7_admin; Password = rU9g9f5GEQsZ;");
ส่วน Connection
ส่วนของ insert
Code (C#)
cn = new SqlConnection("Data Source = sql5026.myasp.net; Initial Catalog = DB_A18CFE_trevorw7; Persist Security Info = True; User ID = DB_A18CFE_trevorw7_admin; Password = rU9g9f5GEQsZ;");
cn.Open();
try
{
string sql = "insert into tblhourly (Traffic_Est,Traffic_Act,Traffic_Total,Txn_Need,Txn_Act,Txn_Total,CR_Target,CR_Act,hdate,Traffic_Hour,BranchID) values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + Label1.Text + "','" + Label2.Text + "','" + TextBox3.Text + "','" + Label3.Text + "','" + TextBox4.Text + "','" + Label4.Text.Replace("%","") + "','" + DateTime.Now.ToShortDateString() + "','10','"+Session["BranchID"].ToString() +"')";
SqlCommand cm = new SqlCommand(sql, cn);
cm.CommandType = CommandType.Text;
cm.CommandText = sql;
cm.ExecuteNonQuery();
}
catch
{
string sql = "update tblhourly set Traffic_Est='" + TextBox1.Text + "',Traffic_Act='" + TextBox2.Text + "',Traffic_Total = '" + Label1.Text + "',Txn_Need = '" + Label2.Text + "',Txn_Act = '" + TextBox3.Text + "',Txn_Total ='" + Label3.Text + "' ,CR_Target = '" + TextBox4.Text + "',CR_Act = '" + Label4.Text.Replace("%", "") + "' where hdate = '" + DateTime.Now.ToString("yyyy-MM-dd") + "' and Traffic_Hour = '10' and BranchID = '"+Session["BranchID"].ToString()+"'";
SqlCommand cm = new SqlCommand(sql, cn);
cm.CommandType = CommandType.Text;
cm.CommandText = sql;
cm.ExecuteNonQuery();
}
cn.close();
จากการลองเปลี่ยน connection ใน Local ของเรา insert ได้ปกติ แต่เปลี่ยน connection ลง server insert ไม่ได้
Tag : .NET, Ms SQL Server 2012, C#
|
|
|
|
|
|
Date :
2017-02-23 15:49:08 |
By :
snowman0020 |
View :
717 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองใช้การดักจับ ex.Message ครับ
|
|
|
|
|
Date :
2017-02-23 17:17:55 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2017-02-24 09:25:52 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|