存储过程不是在web服务中执行,而是在SSMS中执行

本文关键字:执行 SSMS 服务 web 存储过程 | 更新日期: 2023-09-27 18:11:42

我有连接问题与sql server管理工作室(SSMS),当通过web服务连接。

如果我在SSMS中使用帐户xxx登录,我可以执行存储过程。这个用户xxx对存储过程以及这个存储过程使用的所有表的权限是Alter、控制、执行、引用、获取所有权和视图定义。我想我只需要执行。没有问题,存储过程运行良好。

然后,在我的web服务中,我将其设置为运行此存储过程。我使用javascript和SOAP来运行它。它返回一个错误。我已经测试过了,毫无疑问,服务代码和javascript都是正确的。我认为问题在于权限,或者sql中的一些配置。但是我不明白为什么通过一个具有工作帐户的web服务连接到sql不让我运行这个存储过程。

是否有一些我错过了sql权限,就像不使用SSMS。或者,是否有某种方法可以测试我的web服务的连接,这是在c#中?

下面是一些代码,展示了我是如何将它们全部链接起来的。

Web Service Connection (c#):

<connectionStrings>
    <add name="TABLE_NAME" connectionString="Data Source=db_name'instance1;Connect Timeout=30;Initial Catalog=TABLE_NAME;User ID=xxx;PWD=****" />
</connectionStrings>
Web Service Code (c#):
[WebMethod]
public System.Data.DataSet FindThings(string params){
RegistrationDB RegDB = new RegistrationDB();
return RegDB.FindThings(connectionstring, DBHelper.Providers.SqlServer, params);
}
public DataSet FindThings(string connectString, DBHelper.Providers provider, string params){
  DBHelper db = new DBHelper();
  db.CreateDBObjects(connectString, provider);
  DataSet ds;
  try{
    db.AddParameter("@parameters", params);
    ds = db.GetDataSet("[dbo].[procedure_name]", CommandType.StoredProcedure, ConnectionState.Open);
    ds.Tables[0].TableName = "Things";
    ds.Tables[1].TableName = "YearParameters";
  }
  finally{
    db.connection.Close();
  }
  return ds;
}
Javascript:

var webServiceUrl = "/test.asmx";
var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> '
  <soapenv:Body> '
    <FindThings  xmlns='http://tempuri.org/'> '
      <params>" + varParams + "</params> '
    </FindThings> '
  </soapenv:Body> '
</soapenv:Envelope>";
$.ajax({
    url: webServiceUrl,
    type: "POST",
    dataType: "xml",
    data: soapEnv,
    complete: getResult,
    contentType: "text/xml; charset='"utf-8'""
});
function getResult(result, status) {
  if(status != "success"){
    document.getElementById("results").innerHTML += "<p>Status: " + status + "</p>";
  }
}

所以这就是我在网页上得到输出"Status: error"的地方。

有谁知道我应该怎么解决这个问题吗?

存储过程不是在web服务中执行,而是在SSMS中执行

如果您可以访问SQL Server,您还可以查看那里记录的事件或运行Profiler跟踪。可能是您认为用于连接SQL server的用户不在您的部署机器上。通过try/catch获取调试信息是一个很好的解决方案,只是为您提供了另一个选择。

这可能是因为您的服务帐户已被删除。检查这个。我以前遇到过同样的问题