LINQ to SQL Server 2000:“必须声明变量'@ p0'" [英] LINQ to SQL Server 2000: "Must declare variable '@p0'"

查看:152
本文介绍了LINQ to SQL Server 2000:“必须声明变量'@ p0'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了这个简单的LINQ查询:

var result = from invoice in invoiceTable
             where invoice.Id == 1
             select invoice.Document;

它生成此SQL:

SELECT [t0].[Document]
FROM [Invoice] AS [t0]
WHERE [t0].[Id] = @p0

每当我运行它时,都会出现此错误:

(ODBC)

错误[42000] [Microsoft] [ODBC SQL Server驱动程序] [SQL Server]必须声明变量'@ p0'.

(OleDb)

必须声明变量'@ p0'.

我记得读过OleDb和ADO.NET在SQL Server 2000上不支持命名参数.这个问题是否与该问题有关,还是我做错了其他事情?

更新1:

这似乎是提供商的问题.我使用SQL Client数据提供程序对SQL Server 2008尝试了相同的查询,并且工作正常.不幸的是,该提供程序不适用于SQL Server 2000.

当我尝试在SQL Server 2008中使用ODBC和OLEDB提供程序时,出现了相同的错误.

有人知道合适的解决方法吗?

更新2:

事实证明,SQL Client提供程序可以与SQL Server 2000一起使用.只是不在Visual Studio 2010中使用.我更改了提供程序,查询现在可以正常工作.

解决方案

事实证明SQL Client提供程序确实可以与SQL Server 2000一起使用.只是不在Visual Studio 2010中使用.我更改了提供程序,查询现在可以正常工作./p>

I've created this simple LINQ query:

var result = from invoice in invoiceTable
             where invoice.Id == 1
             select invoice.Document;

It generates this SQL:

SELECT [t0].[Document]
FROM [Invoice] AS [t0]
WHERE [t0].[Id] = @p0

Whenever I run it though I get this error:

(ODBC)

ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the variable '@p0'.

(OleDb)

Must declare the variable '@p0'.

I remember reading that OleDb and ADO.NET does not support named parameters on SQL Server 2000. Is this problem related to that issue, or am I doing something else wrong?

UPDATE 1:

This does seem to be a provider issue. I tried the same query against SQL Server 2008 using the SQL Client data provider and it worked fine. Unfortunately, this provider does not work with SQL Server 2000.

When I tried using the ODBC and OLEDB providers with SQL Server 2008 I got the same errors.

Does anyone know of a suitable workaround?

UPDATE 2:

It turns out the SQL Client provider does work with SQL Server 2000. Just not from within Visual Studio 2010. I changed the provider and the query works now.

解决方案

It turns out the SQL Client provider does work with SQL Server 2000. Just not from within Visual Studio 2010. I changed the provider and the query works now.

这篇关于LINQ to SQL Server 2000:“必须声明变量'@ p0'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆