Reputation: 901
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:
this is in English as supposed to.
Now when i try the same in C# i will get:
which is in german.
What am i missing? Any ideas anyone? Thanks very much...
Upvotes: 2
Views: 718
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