0

enter image description hereI am using SQL CE version 3.5.1. On my PC everything works fine but on the clients PC it generates the following error. I'm doing model first.

The ntext and image data types cannot be used in WHERE, HAVING, GROUP BY, ON, or IN clauses, except when these data types are used with the LIKE or IS NULL predicates.

I don't have any ntext or image data types. I found a couple of different posts describing a similar problem but none of the solutions fixed my issue.

I reviewed the following post The Ntext And Image Data Types Cannot Be Used In WHERE, HAVING, GROUP BY, ON, Or IN Clauses I'm not using any varchar(max) or varbinary(max) which is what this post references. I am including the sqlce dlls with the application so I don't believe it is referencing a different version but I'm waiting to find out what the client all has installed before I can confirm. I have been unable to reproduce the issue on a vm, and on my workstation.

Here is the sql that was generated when the error occurred.

SELECT 1 AS [C1],
[Extent1].[ID] AS [ID], 
[Extent1].[ID] AS [ID], 
[Extent1].[FirstName] AS [FirstName], 
[Extent1].[LastName] AS [LastName], 
[Extent1].[SLID] AS [SLID], 
[Extent1].[Password] AS [Password], 
[Extent1].[CreatedBy] AS [CreatedBy], 
[Extent1].[CreatedDate] AS [CreatedDate], 
[Extent1].[LastUpdatedBy] AS [LastUpdatedBy], 
[Extent1].[LastUpdatedDate] AS [LastUpdatedDate], 
[Extent2].[ID] AS [ID1], 
[Extent2].[Name] AS [Name]
FROM [Users] AS [Extent1]
LEFT OUTER JOIN [Roles] AS [Extent2] ON [Extent1].[RoleID] = [Extent2].[ID]
WHERE ([Extent1].[SLID] = @p__linq__1) AND ([Extent1].[Password] = @p__linq__2)

This is generated from the following linq query.

var user = (from u in entities.Users.Include("Role")
    where u.SLID == txtSLID.Text &&
    u.Password == passwordHash
    select u).FirstOrDefault<User>();

UPDATE Added Table Schema

Community
  • 1
  • 1
CodeHulk
  • 111
  • 1
  • 12

4 Answers4

0

If you are using the MS Sql Server Compact Version 3.5 with the service pack 1, then following link might help you:

http://support.microsoft.com/kb/958478#appliesto

Somebody wrote "SQL Server Compact does not support the nvarchar(max) data type or the varbinary(max) data type. The provider may mark the nvarchar(max) data type parameter as the ntext data type or as the image datatype, an error occurs if any equality operations, grouping operations, or sorting operations are being performed on the parameter.

This problem has been confirmed and fixed by Microsoft." from http://answers.flyppdevportal.com/categories/sqlserver/sqlce.aspx?ID=eca752c8-f921-44cf-a35b-5ecb14cc3134>

user3840527
  • 71
  • 1
  • 2
0

Use EF 6 and EntityFramework.SqlServerCompact package, and it all will Work.

ErikEJ
  • 40,951
  • 5
  • 75
  • 115
0

I am using EF 6 with MS visual studio 2010 and MS Sql server compact 3.5 SP 2. I also experience the same issue with Linq, maybe because of the service pack 2. I tried to contact microsoft in order to ask if there is no fix for the sp 2 because the linked hotfix for sp1 does not work in this case.

user3840527
  • 71
  • 1
  • 2
0

I think I just found out what is really going on:

-> looking at your connection properties in the screen shot in your question I can see that your database is stored in a sdf file. You probably want to use a local database but didn't pay attent like I did to the type of the database.

-> using EF6 and trying to generate code (domain classed) from an existing local database (mdf file), I noticed that it is possible to setup the connection to the existing mdf database via the option MS SQL SERVER or to a sdf database via the option MS SQL SERVER COMPACT

-> looking at the difference between a sdf and mdf database I found this When to use .mdf and when .sdf? and this http://erikej.blogspot.de/2011/01/comparison-of-sql-server-compact-4-and.html

-> I tried in my case now the use the existing mdf database instead of creating a new sdf database. In that way I could perfectly use my LINQ code in my application without any problem. It is not only a matter service pack 2 with Ms Sql Server Compact 3.5 or hotfix, we need to target the right database type when we are coding our application

I hope this helps.

Community
  • 1
  • 1
user3840527
  • 71
  • 1
  • 2