sql server插入查询在本地工作但不在托管服务器上工作?

发布于 2025-01-06 18:16:57 字数 2844 浏览 0 评论 0原文

当我使用以下代码插入表中时,它在本地测试/开发服务器上工作正常,但是当我将其上传到网络托管服务器时,它不起作用,也不会引发错误或异常。

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();
    }

when I use the following code to insert into a table it works fine on my local testing/development server, but when I upload it to the webhosting server it doesn't work, and won't throw an error or exception either.

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();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黎歌 2025-01-13 18:16:57

首先,网络服务器是在本地计算机上吗?如果是这样,则不会发生网络问题,但正如 JeremyK 所说,很可能是权限问题。查明您的网络托管服务器的数据库是否需要用户名和密码(大多数情况下需要),然后只需编辑数据库的连接字符串即可。

Firstly is the webserver on a local machine? If so then there is no network problems that can occure but as stated by JeremyK it could very well be the permissions. Find out if your webhosting server's database needs a username and password (Most cases it is) and then just edit your connection string to the database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文