0

I have a SQL Server in Azure, with default language eu_english. That means that the dates are in format mdy and I need them in dmy, I want to put the language to Spanish in the connection string. I have tried this. but it doesn't work:

jdbc:sqlserver://myazureURL:1433;DatabaseName=MyDataBase;Language=Spanish

I have tried adding Language=Spanish, but it doesn't work. I have also tried Language=5 because 5 is the Spanish Id of languages of my SQL Server.

I need this because I can't change default language from database settings. If I try to change default language with that:

EXEC sp_configure 'default language', 'Spanish';

It gives me this error:

EXEC sp_configure 'default language', 'Spanish';

EDIT WITH SOLUTION: I solved it incluiding this to the connection String so in each connection it sets the language:

 connectionInitSqls ="SET LANGUAGE Spanish"
12
  • What is the error message ? Commented Jun 27, 2022 at 8:36
  • @Squirrel there is no error message but the connection still with sql server language us_english and not Spanish Commented Jun 27, 2022 at 9:03
  • To me it seems you are mistaking something. eu_english has format yyyy-MM-dd. The format mdy is something you would rather find in the US. And you most probably don't even need to change the language, just properly parse the parameters, which should automatically happen if you use PreparedStatement Commented Jun 27, 2022 at 9:08
  • 2
    The default language is determined by the login. But this is likely a XY problem that is better address by changing your application code. Usually this implies a sql injection problem where you create SQL statements using string concatenation. Commented Jun 27, 2022 at 9:51
  • 1
    The database language should be completely irrelevant. Are using parameterized queries and sending java.util.Date values via DATE JDBC type parameters? If you need to change the database language to make your code work then it sounds like you are subject to SQL Injection attacks because you're concatenating string snippets to construct SQL queries. Commented Jun 27, 2022 at 10:03

2 Answers 2

0

According to the post Change the default language of Azure SQL Database given by @Jose Manuel Jurado Diaz.

Currently, using stored procedures or at logging time using T-SQL to set the default language at the server level is not supported.

As, System messages and datetime formats are determined by the session language.

The workaround for this is to use the following command.

  • To mention language in connection string you can specify this keyword Current Language with the language you want ex. Current Language=Spanish

  • If the connection is already established

SET LANGUAGE Spanish;

Changed language from us_english to Spanish and get date format from MDY to DMY

Below is the sample code and output result:

SELECT @@language;
select format(getdate(),'d');
SET Language Spanish;
SELECT @@language;
select format(getdate(),'d');

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

I have updated my answear i solved with something similar , i set the language on the connection string
0

Some drivers dont have support to Language= or Current Language= on ConnectionString, so the solution is to execute the SQL command after the sucessfull connection, "SET LANGUAGE Spanish;"

Other solution is on SQL Server set the default language to your desired user. One way is using Management Studio, click with right button on user, choose properties and so change the Default Language to that user.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.