當我使用下面的代碼插入到表中時,它可以在我的本地測試/開發服務器上正常工作,但是當我將它上載到webhosting服務器時,它不起作用,並且不會拋出錯誤或異常。sql服務器插入查詢本地但不在託管服務器上工作?
public void insertEnq(List<string> valuesparam)
{
SqlConnection thisConnection = new SqlConnection([//connection string details]);
//Create Command object
SqlCommand nonqueryCommand = thisConnection.CreateCommand();
try
{
// Open Connection
thisConnection.Open();
// Create INSERT statement with named parameters
nonqueryCommand.CommandText = "Insert Into [project].[dbo].[LP_Records]("
+ "f_name, "
+ "l_name, "
+ "email, "
+ "country, "
+ "country_code, "
+ "phone_no, "
+ "interested_in, "
+ "area, "
+ "comments, "
+ "page_url, "
+ "page_refferal)"
+ " Values "
+"(@F_Name, "
+ "@L_Name, "
+ "@Email, "
+ "@Country, "
+ "@Country_Code, "
+ "@Phone_No, "
+ "@Interested_In, "
+ "@Area, "
+ "@Comments, "
+ "@Page_URL, "
+ "@Page)";
// Add Parameters to Command Parameters collection
nonqueryCommand.Parameters.Add("@F_Name", SqlDbType.VarChar, 50);
nonqueryCommand.Parameters.Add("@L_Name", SqlDbType.VarChar, 50);
nonqueryCommand.Parameters.Add("@Email", SqlDbType.VarChar, 50);
nonqueryCommand.Parameters.Add("@Country", SqlDbType.VarChar, 50);
nonqueryCommand.Parameters.Add("@Country_Code", SqlDbType.VarChar, 50);
nonqueryCommand.Parameters.Add("@Phone_No", SqlDbType.VarChar, 50);
nonqueryCommand.Parameters.Add("@Interested_In", SqlDbType.VarChar, 50);
nonqueryCommand.Parameters.Add("@Area", SqlDbType.VarChar, 50);
nonqueryCommand.Parameters.Add("@Comments", SqlDbType.VarChar, 2000);
nonqueryCommand.Parameters.Add("@Page_URL", SqlDbType.VarChar, 50);
nonqueryCommand.Parameters.Add("@Page", SqlDbType.VarChar, 50);
nonqueryCommand.Parameters["@F_Name"].Value = valuesparam[1];
nonqueryCommand.Parameters["@L_Name"].Value = valuesparam[2];
nonqueryCommand.Parameters["@Email"].Value = valuesparam[3];
nonqueryCommand.Parameters["@Country"].Value = valuesparam[7];
nonqueryCommand.Parameters["@Country_Code"].Value = valuesparam[8];
nonqueryCommand.Parameters["@Phone_No"].Value = valuesparam[10];
nonqueryCommand.Parameters["@Interested_In"].Value = valuesparam[5];
nonqueryCommand.Parameters["@Area"].Value = valuesparam[6];
nonqueryCommand.Parameters["@Comments"].Value = Request["txtEnquiry"];
nonqueryCommand.Parameters["@Page_URL"].Value
= Request.UrlReferrer.ToString();
nonqueryCommand.Parameters["@Page"].Value = valuesparam[0];
nonqueryCommand.ExecuteNonQuery();
}
檢查您的連接字符串,您需要的字符串可能與生產服務器和本地服務器不同。 – 2012-02-17 12:50:44
發佈您正在收到的錯誤。可能是權限,端口設置,防火牆等等。聽起來就像您沒有將服務器配置爲通過網絡工作。 – JeremyK 2012-02-17 12:52:16
我得到沒有錯誤 – 2012-02-17 12:58:34