【发布时间】:2019-08-16 21:08:18
【问题描述】:
Database.LoadDataSet 在 SQL Server 2017 数据库中工作不正确。
我们正在将数据库从 SQL Server 2008 R2 迁移到 SQL Server 2017。数据库是使用兼容模式 100 创建的 - 与 SQL Server 2008 R2 兼容。我被一些旧代码卡住了,这会产生没有信息的异常。
Database.LoadDataSet 命令有问题,它正在调用存储过程,它接受 2 个参数。使用 SQL Server 2008 R2 可以正常工作,但使用 SQL Server 2017 会失败。错误是没有足够的 SQL 参数。但有趣的是传递了足够多的参数。我正在寻找解决方案,将旧数据库与新数据库进行比较,数据库和存储过程的属性似乎相同。
IIS 应用程序池上的 .NET CLR 版本:2.0
.NET 目标框架版本:3.5
//.NET C# code:
DataSet dataset;
Database db = DatabaseFactory.CreateDatabase();
db.LoadDataSet(
"USP_Proc",
dataset,
new string[] {"Titles", "Config", "Teams"},
Request.QueryString["Type"],
int.Parse(Request.QueryString["BranchID"]));
//SQL Procedure:
SET ANSI_NULLS OFF
SET QUOTED_IDENTIFIER ON
ALTER PROCEDURE [dbo].[USP_Proc]
@BranchType VARCHAR (15), @BranchId [dbo].[ID]
AS
SELECT
TitleId, Title
FROM vOperatorTitles
ORDER BY Title
IF @BranchType = 'L'
BEGIN
SELECT OperatorTeams
FROM tCustomerConfig
WHERE CustomerId = @BranchId
SELECT TeamId, TeamName
FROM tTeams
WHERE CustomerId = @BranchId
END
SELECT count(*) as ISSTAGEMANAGEMENT
FROM tfeature_branch
WHERE
branchid=@BranchId and
systemside=@BranchType and
featureid = (select featureid from tfeature where featurecode= 'somecode')
Expected: there is no errors (as on environments which use old SQL Server)
Actual:
When calling db.LoadDataSet, there is an error:
[InvalidOperationException: The number of parameters does not match number of values for stored procedure.]
Microsoft.Practices.EnterpriseLibrary.Data.Database.GetStoredProcCommand(String storedProcedureName, Object[] parameterValues) +384
Microsoft.Practices.EnterpriseLibrary.Data.Database.LoadDataSet(String storedProcedureName, DataSet dataSet, String[] tableNames, Object[] parameterValues) +42
SupportConsole.Pagelets.OperatorAdd.Page_Load(Object sender, EventArgs e) in E:\Source\Pagelets\OperatorAdd.ascx.cs:88
System.Web.UI.Control.OnLoad(EventArgs e) +132
System.Web.UI.Control.LoadRecursive() +66
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
【问题讨论】:
-
我不熟悉这个
.LoadDataSet方法,记录在哪里? -
Request.QueryString["Type"]的值是多少? 请签入Immediate Window? -
值:类型:'L',BranchId:3
-
你能直接使用
exec命令运行sp吗:exec [dbo].[USP_Proc] BranchType = 'L', BranchId=3
标签: c# .net sql-server server