LINQ to SQL Server 2000: “Must declare variable '@p0'”

不羁的心 提交于 2019-12-24 04:27:07

问题


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.


回答1:


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.




回答2:


If you are using an ODBC provider, it will not work. Change to SqlClient.



来源:https://stackoverflow.com/questions/10016456/linq-to-sql-server-2000-must-declare-variable-p0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!