是什么原因导致我的SQL Server权限从一个存储过程的一次执行更改为下一次执行
本文关键字:执行 一次 存储过程 一个 Server SQL 我的 权限 是什么 | 更新日期: 2023-09-27 18:26:50
我使用的存储过程在第一次执行时运行,不会抱怨权限问题。存储过程只设置了一个UID/PWD(没有用于授予不同权限级别的不同UID/PW集)。单个对提供了对所有内容的权限。
我调用存储过程的代码是:
DataTable dtPriceComplianceResults
SQLDBHelper.ExecuteSQLReturnDataTable(PriceComplianceConstsAndUtils.SUMMARY_STOREDPROC, CommandType.StoredProcedure,
new SqlParameter()
{
ParameterName = "@BegDate",
SqlDbType = SqlDbType.VarChar,
Value = _begDateStr
},
new SqlParameter()
{
ParameterName = "@EndDate",
SqlDbType = SqlDbType.VarChar,
Value = _endDateStr
},
new SqlParameter()
{
ParameterName = "@Member",
SqlDbType = SqlDbType.VarChar,
Value = _member
},
new SqlParameter()
{
ParameterName = "@Unit",
SqlDbType = SqlDbType.VarChar,
Value = _unit
});
public static DataTable ExecuteSQLReturnDataTable(string sql, CommandType cmdType, params SqlParameter[] parameters)
{
using (DataSet ds = new DataSet())
using (SqlConnection connStr = new SqlConnection(PriceComplianceConstsAndUtils.CPSConnStr))
using (SqlCommand cmd = new SqlCommand(sql, connStr))
{
cmd.CommandType = cmdType;
cmd.CommandTimeout = EXTENDED_TIMEOUT;
foreach (var item in parameters)
{
cmd.Parameters.Add(item);
}
try
{
cmd.Connection.Open();
new SqlDataAdapter(cmd).Fill(ds);
}
catch (SqlException sqlex)
{
for (int i = 0; i < sqlex.Errors.Count; i++)
{
var sqlexDetail = String.Format("From ExecuteSQLReturnDataTable(), SQL Exception #{0}{1}Source: {2}{1}Number: {3}{1}State: {4}{1}Class: {5}{1}Server: {6}{1}Message: {7}{1}Procedure: {8}{1}LineNumber: {9}",
i + 1, // Some users would get the fantods if they saw #0
Environment.NewLine,
sqlex.Errors[i].Source,
sqlex.Errors[i].Number,
sqlex.Errors[i].State,
sqlex.Errors[i].Class,
sqlex.Errors[i].Server,
sqlex.Errors[i].Message,
sqlex.Errors[i].Procedure,
sqlex.Errors[i].LineNumber);
MessageBox.Show(sqlexDetail);
}
}
catch (Exception ex)
{
String exDetail = String.Format(PriceComplianceConstsAndUtils.ExceptionFormatString, ex.Message, Environment.NewLine, ex.Source, ex.StackTrace);
MessageBox.Show(exDetail);
}
return ds.Tables[0];
}
}
这是存储过程的第一部分:
ALTER procedure [dbo].[sp_duckbilled_platypus]
@BegDate varchar(10),
@EndDate varchar(10),
@Member varchar(max),
@Unit varchar(max)
AS
drop table zDistDBPExceptions
select (ph.memberno), TotalDesExceptions=1
into zDistDBPExceptions
from priceexceptionshistory ph
inner join MasterUnits MU on ph.Unit=MU.Unit
Inner Join Members M on ph.memberno = M.MemberNo
where ph.memberNo not in ('04501','04503') --,'111','B140')
and ph.memberno in (select [value] from dbo.split(@member,','))
and ph.Unit in (select [value] from dbo.Split(@Unit,','))
and invoicedate between @BegDate and @EndDate
and filtered=0
and abs(contractprice) = 0
and abs(ph.pricepush) = 0
and bidprice > 0
and abs(MU.TruTrack) = 1
and abs(ph.pricesheet) = 1
drop table zContractDBPExceptions
select (ph.memberno), TotalContractExceptions=1
into zContractDBPExceptions
from priceexceptionshistory ph
inner join MasterUnits MU on ph.Unit=MU.Unit
Inner Join Members M on ph.memberno = M.MemberNo
where ph.memberNo not in ('04501','04503') --,'111','B140')
and ph.memberno in (select [value] from dbo.split(@member,','))
and ph.Unit in (select [value] from dbo.Split(@Unit,','))
and invoicedate between @BegDate and @EndDate
and filtered=0
and abs(contractprice) = 1
and abs(ph.pricepush) = 1
and bidprice > 0
and abs(MU.TruTrack) = 1
drop table zDBPExceptions
select (ph.memberno), TotalPriceSheetExceptions=1--, invoicedate
into zDBPExceptions
from priceexceptionshistory ph
inner join MasterUnits MU on ph.Unit=MU.Unit
Inner Join Members M on ph.memberno = M.MemberNo
where ph.memberNo not in ('04501','04503') --,'111','B140')
and ph.memberno in (select [value] from dbo.split(@member,','))
and ph.Unit in (select [value] from dbo.Split(@Unit,','))
and invoicedate between @BegDate and @EndDate
and filtered=0
and abs(contractprice) = 0
and abs(ph.pricepush) = 1
and bidprice > 0
and abs(MU.TruTrack) = 1
drop table zSumtDBPExceptions
select (ph.memberno), TotalSumExceptions=1
into zSumtDBPExceptions
from priceexceptionshistory ph
inner join MasterUnits MU on ph.Unit=MU.Unit
Inner Join Members M on ph.memberno = M.MemberNo
where ph.memberNo not in ('04501','04503') --,'111','B140')
and ph.memberno in (select [value] from dbo.split(@member,','))
and ph.Unit in (select [value] from dbo.Split(@Unit,','))
and invoicedate between @BegDate and @EndDate
and filtered=0
and bidprice > 0
and abs(MU.TruTrack) = 1
and abs(ph.pricesheet) = 1
--this gets all invoice data
--insert into PriceExceptionsHistory
-- *** zContractDBPBase ***
drop table zContractDBPBase
. . .
发生的一件非常奇怪的事情(ISTM)是,昨天存储过程根本无法运行,告诉我要么被丢弃的表(所有表都被丢弃在存储过程中,每个表都依次列出)不存在,要么我没有访问它们的权限。它们确实都存在。因此,权限似乎是个问题。
然而,今天上午,在没有更改代码或数据库的情况下,存储过程最初运行时没有抱怨权限问题(仅是第一次)。
然而,在第二次执行时,它抱怨我没有zContractDBPBase表的权限。我想我现在有权删除前四个,但没有这个。。。?!?
IOW,我得到的错误消息(在"Query completed with errors"之后)现在是:
消息3701,级别11,状态5,过程sp_zDBP_pella,第80行
无法删除表"zContractDBPBase",因为它不存在或您没有权限。
而以前是相同的消息,但对于所有丢弃的表,而不仅仅是一个。
那么,为什么权限是可变的呢?我刷新了表的列表,仍然可以看到我显然没有权限访问的表("zContractDBPBase");在Visual Studio IDE中的服务器资源管理器和LINQPad中刷新时都可以看到它。
我需要做什么(除了更改存储过程本身,这超出了我的职责和专业知识范围)才能让存储过程允许"我"删除表?
Pikoh的评论让我回到了我之前想知道的事情上——同时运行LINQPad是否有问题——LINQPad"用户"和Visual Studio"用户"都挂在了这些连接或SP上,或者是导致了混乱的原因。
我关闭了LINQPad,再也没有这些问题了——既没有通过VS中的服务器资源管理器运行SP,也没有通过应用程序中的C#代码运行SP。
我喜欢LINQPad,但它显然不能很好地与SQL Server配合使用,反之亦然。