我有一个 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"."
}
关于如何解决这个问题的任何建议?