【问题标题】:Queries work in debug mode but not in deployment mode?查询在调试模式下工作,但在部署模式下不工作?
【发布时间】:2012-04-19 03:59:56
【问题描述】:

我有一个 C# 应用程序,以下是我的 Web.config 文件的摘录:

  <connectionStrings>
    <add name="MyDB" connectionString="Data Source=MACHINENAME\\SQLEXPRESS;Initial Catalog=DBName;Integrated Security=True;MultipleActiveResultSets=true" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <authentication mode="Windows" />
    <identity impersonate="false" />
  </system.web>

在代码本身中,我有这样的查询:

[WebMethod]
public string InsertField(string str1, string str2, string str3)
{

    string sql = @"
          UPDATE DBNAME.dbo.TableName SET Field2 = '{2}', Modified_At=GETDATE() WHERE Field1 = '{0}' AND Field2 = '{1}';

          IF @@ROWCOUNT = 0
              INSERT INTO DBNAME.dbo.TableName (Field1, Field2, Field3, Modified_At)
              VALUES('{0}', '{1}', '{2}', GETDATE())
            ";

    sql = String.Format(sql, str1, str2, str3);

    try
    {
          string ConString = Constants.connString;
          con = new SqlConnection(ConString);

          cmd = new SqlCommand(sql, con);
          con.Open();
          cmd.ExecuteNonQuery();
          return "Success";
    }
    catch (Exception x)
    {
          return x.Message;
          //Response.Write(x);
     }

}

我的 Web 应用程序在调试时运行良好,但在发布时,查询失败。使用 Firebug 进行调试会产生以下错误:

{
    "d": "The UPDATE permission was denied on the object "TableName", database "DBName", schema "dbo".\r\nThe INSERT permission was denied on the object "TableName", database "DBName", schema "dbo"."
}

关于如何解决此问题的任何建议?

【问题讨论】:

    标签: c# sql sql-server sql-server-2008 permissions


    【解决方案1】:

    是的,这是一个非常明显的错误。您需要确保您的网站设置为运行的任何帐户都应该有权更新/插入给定的表。

    由于用户似乎没有在连接字符串中设置。它将使用任何运行的 web 方法。所以,find out what that account isgrant 是适当的烫发。它在开发中有效,因为它可能在您的帐户下运行,该帐户可能对您的开发数据库具有完全访问权限。

    【讨论】:

      【解决方案2】:

      用户没有足够的权限在您的生产环境中执行更新。 您必须向您正在运行的用户授予更新权限

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-12-09
        • 1970-01-01
        • 1970-01-01
        • 2015-08-16
        • 2022-01-20
        • 1970-01-01
        • 2018-07-31
        • 1970-01-01
        相关资源
        最近更新 更多