Felix Almesberger
Felix Almesberger

Reputation: 901

Entity Framework SQL Server Error Message Language

I am working on an Application utilizing Entity Framework for Data Access. For some purposes it is neccessary to parse the SqlException Message for further information. I already found out that this Exception Message is directly coming from SQL Server. So to make that parsing process work i need to make sure the language is set to the same in every environment.

I am using to set the language

SET LANGUAGE English;

For test purposes I did following:

SET LANGUAGE English;
SELECT * FROM ABC;

ABC does not exist so it will obviously fail and i will get an error message. In Management Studio my ErrorMessage is showing this:

enter image description here

this is in English as supposed to.

Now when i try the same in C# i will get:

enter image description here

which is in german.

What am i missing? Any ideas anyone? Thanks very much...

Upvotes: 2

Views: 718

Answers (1)

Steve
Steve

Reputation: 11973

instead of doing this in two ExecuteSqlCommand calls you should do this in one.

string command = "SET LANGUAGE English; SELECT * FROM ABC;";
ctx.Database.ExecuteSqlCommand(command);

ExecuteSqlCommand will start a new auto commit session. Your first SET LANGUAGE pretty much has no effect since the select is in another session.

Upvotes: 3

Related Questions