Database.LoadDataSet无法与SQL Server 2017数据库一起使用。
我们正在将数据库从SQL Server 2008 R2迁移到SQL Server2017。数据库以兼容模式100创建-与SQL Server 2008 R2兼容。我受困于一些旧代码,这些代码不会产生信息丰富的异常。
命令Database.LoadDataSet出现问题,该命令正在调用存储过程,该过程接受2个参数。使用SQL Server 2008 R2可以正常工作,但是使用SQL Server 2017则可以失败,错误是没有足够的SQL参数。但有趣的是,有足够的参数传递。我试图找到一种解决方案,将旧数据库与新数据库进行比较,并且数据库和存储过程的属性似乎相同。
IIS应用程序池上的.NET CLR版本:2.0
.NET target Framework版本: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
答案 0 :(得分:0)
您的参数应该在数组中
db.LoadDataSet("USP_Proc",
dataset,
new string[] {"Titles", "Config", "Teams"},
new object[] { Request.QueryString["Type"], int.Parse(Request.QueryString
["BranchID"])});