Existing LINQ to Entities queries throw exception on upgrade to VS 2017 - vb.net

We recently upgraded our visual studio from 2013 to 2017, are working on with EntityFramework 6.1.3, and with the upgrade have our projects targetting the 4.7 .NET Framework. With these changes we have existing LINQ queries that are breaking on us.
A simplified example:
Dim comm = Communication.Where(Function (t) t.Id = 1).ToList()
Dim query = (From cc In comm
Let a = ""
Select New With {
.UserName = (From e In Employee
Where e.Initials = cc.EmployeeInitials
Select ee.UserName).FirstOrDefault()
}
)
In this situation the result will be a System.NotSupportedException with the message being:
LINQ to Entities does not recognize the method 'Company.Core.Models.Communication get_cc()'
Now removing the Let statement from the query fixes the exception and the query will run fine, however I cannot determine why the Let causes problems and more specifically why this query only recently broke.
So I am hoping someone can give a explanation of why this exception cropped up in VS 2017 when it had worked fine in VS 2013 and in our production system for years.

Related

Why am I getting antlr.MismatchedTokenException thrown for simple SQL query parsing (.NET)?

Queries are read fine when debugging only My Code. However, when disabling the option in Visual Studio in 'Debug > Options > Enable Just My Code', antlr.MismatchedTokenException is thrown for almost every SQL query which is run through the parser.
Here's a simplified example, which throws:
antlr.MismatchedTokenException 'expecting "Dot", found 'AS''
Ignoring the exceptions, the select statement works fine and is passed to the app no problem. But the constant spam of .NET exceptions is puzzling. The literal interpretation of the exception doesn't seem to make sense for this SQL query.
I can't see anything wrong with this example query.
private static StatementList PrepareSql(string sql)
{
sql = "SELECT A.[ID] AS [Activities_Id] FROM [Activities] A";
var parser = new TSql140Parser(false, SqlEngineType.SqlAzure);
return parser.ParseStatementList(new StringReader(sql), out var errors1);
}
--
Update:
We believe the exception occurs not in the immediate library referenced by the portal, but in ANTLR. We still cannot find the reason for the exception. Currently we've added a workaround to cache the SQL query so that the exception is only thrown once per query - but that's still one too many.

Microsoft ACE DatabaseEngine 2010 driver (12.0) Problem, after Windows 10 1909 Cumulative Updates (and later)

since cumulative Windows 10 1909 Updates are installed, I get following exception when accessing MS Access accdb.
: An external component raised an exception.
After reinstalling Microsoft ACE DatabaseEngine 2010 (OLEDB.12.0 ..), all works fine again.
What can I do about it?
Dim sel As String = "Select Notiz from T_TerminNotiz where ztrText=#ztrText and serNr=#serNr"
Using myConnection As New OleDbConnection(myConnStringX1)
myConnection.Open()
Using mySqlCmd As New OleDbCommand(sel, myConnection)
mySqlCmd.CommandType = CommandType.Text
mySqlCmd.CommandTimeout = myCmdTimeOut
mySqlCmd.CommandText = sel
mySqlCmd.Parameters.Clear()
mySqlCmd.Parameters.Add(New OleDbParameter("#ztrText", OleDbType.VarChar)).Value = strKlient
mySqlCmd.Parameters.Add(New OleDbParameter("#serNr", OleDbType.Integer)).Value = serNr
oRet = mySqlCmd.ExecuteScalar()
End Using
End Using
Microsoft announces (Known issues with Office and Windows 10) that included Office 2010, but did not specify any technical details for developers.
However, you did the best thing, considering that you will (anyway) provide DatabaseEngine 2010 Redist for the client.
Sometimes, the problem is
due to a mismatch between the build configuration platform of your
project and the Microsoft Access Database Engine which is installed on
your machine.
As stated in this answer [by/ Katia]. Hope this helps. Best of luck.
after some tests, I found following solution to my problem.
Installing Microsoft DatabaseEngine 2016.
I activated all OLE DB Services by adding it into configuration file xxx.config.
...
connectionString="Provider=Microsoft.ACE.OLEDB.16.0;Data Source=Table.accdb;Persist Security Info=True;OLE DB Services=-1;

SQL looking for a part number ending in '~0000'

I am trying to find records ending in ~0000 such as ABC~0000
but everything I try doesn't seem to work. Some examples:
and left (mfr_part_number, 4) = 'ABC~' -- finds nothing
and left (mfr_part_number, 3) = 'ABC' -- finds stuff
AND RIGHT(MFR_PART_NUMBER, 4) = '0000' -- finds nothing
AND RIGHT(MFR_PART_NUMBER, 5) = '~0000' -- finds nothing
and DbFunctions.Like(MFR_PART_NUMBER,'%0000') -- suggested elsewhere, but not recognized in MSSMS.
I am using:
SQL Server Management Studio 15.0.18206.0
Microsoft Analysis Services Client Tools 15.0.1567.0
Microsoft Data Access Components (MDAC) 10.0.18362.1
Microsoft MSXML 3.0 6.0
Microsoft .NET Framework 4.0.30319.42000
Operating System 10.0.18363
Thanks!
Are you using all of those AND statements in your WHERE clause? If so, that would cause nothing to return if there's no data that matches all criteria.
Try
SELECT column1, column2...
FROM yourdb
WHERE MFR_PART_NUMBER LIKE '%0000'

Oracle 9i ignores query alias sent from vb.net

The following code is from a released version of an application using framework version 1 and Oracle 9i.
strSQL = "SELECT COURSE_CODE AS CODE FROM COURSE_REVISIONS WHERE DOC_REF_CODE = '" & doc_ref_prevcode & "'"
objDataset = stkDataAssistant.getTable(strSQL)
course_code = objDataset.Tables(0).Rows(0)("Course_Code").ToString
Response.Redirect("../Courses/CourseRevisionNew.aspx?flag=add&course_code=" & course_code)
It is throwing an error on the following line:
course_code = objDataset.Tables(0).Rows(0)("Course_Code").ToString
It is known that there is an error in the sql string with the alias CODE. This issue was being ignored in the clients environment and was working until a month ago that is now throwing an error in the stated line above.
Is this error showing up now because of some sort of framework change? Or is it with Oracle?
The client states that there has been updates to the server where the database resides but the application was still working as expected. The error started showing up 3 months later and there has no changes done to either the database or application environment.
Oracle 9i has been out of support for many, many years. However you have to work with what you have, try this:
SELECT "COURSE_REVISIONS"."COURSE_CODE"
FROM "COURSE_REVISIONS"
WHERE "COURSE_REVISIONS"."DOC_REF_CODE" = 'QDMSPROD';
Or you could make a view with the alias that you want and select from that.

Delphi - Either BOF or EOF is True, or the current record has been deleted

This error showed when I tried to select on an empty table in MS SQL Server 2005: "either BOF or EOF is True, or the current record has been deleted". I have used TADOConnection and TADODataSet in Delphi 5 to connect and retrieve data from the database.
Conn := TADOConnection.Create(nil);
DataSet := TADODataSet.Create(nil);
Conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=sa;' +
'Persist Security Info=True;' +
'User ID=user;Initial Catalog=mydb;' +
'Data Source=MYPC\SQLEXPRESS;' +
'Use Procedure for Prepare=1;' +
'Auto Translate=True;Packet Size=4096;' +
'Workstation ID=MYPC;' +
'Use Encryption for Data=False;' +
'Tag with column collation when possible=False';
Conn.LoginPrompt := False;
Conn.Open;
DataSet.Connection := Conn;
DataSet.CommandText := 'SELECT * FROM MYTABLE';
DataSet.Open;
DataSet.Free;
Conn.Free;
Is there a way to check if a database table is empty without incurring such error?
This error originally occured with an update to MDAC_TYP (to 2.6 from memory). According to an old Borland advisory
"This is a bug in the SQL Server provider. Set
CursorLocation = clUseClient to eliminate the error."
There was a ADOExpress patch available from Borland, but the link doesn't work. Embarcadero now host it here: ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe(Thanks for the official link Jeroen!)
I would recommend downloading and installing all patches listed on the Embarcadero site, assuming you can find them.
Download the ADO update for Delphi 5 here: ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe
Make sure you also have the regular update installed:
English Enterprise
English Professional
English Standard
There are more updates (Corba, original ADO install) and languages (French, German), but these should get you going.
There also used to be a http://info.borland.com/devsupport/delphi/download_files/zlibupdate.zip, but it is not on the ftpd servers.
--jeroen
It was long time agom but I recall that this problem in Delphi 5 resolves by Delphi update. Early version has serious problems with ADO components
P.S. Also I see that your code uses not typical runtime creation of components and does not use some container like data module or form (not good usually) for visual work with components. Also sometimes useful run simple queries via adoConnection.execute. If you do not use visual components, handling of ADO's Recordset object is much the same as Delphi's AdoDataset.
Since I spent a whole day on this, here is a wrap up of what I did in the end.
Delphi 5 Pro Installation with ADO Express
Uninstall Delphi 5, also deleted installation directory
Install Delphi 5 Pro (I only have a German Delphi Pro edition available)
Install Delphi 5 Pro Update (I used the German update)
Install Delphi 5 ADO Express
Install Delphi 5 ADO Express Update Pack 1
Install Delphi 5 ADO Express Update Pack 2
And the download links (many thanks again Jeroen Wiert Pluimers):
Delphi 5 Pro updates:
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/delphi5/D5ProUpdate.exe
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/delphi5/german/d5proupdate.exe
ADOExpress Update Packs 1 and 2:
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/D5ADOUpgrade.exe
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe
And for future reference some screenshots to build the download links (case sensitive):