skip to Main Content

My problem is that I get the following error, although I have updated the config for my Symfony project. Here is the problem:

An exception occurred in the driver: SQLSTATE [IMSSP, -48]: The encoding 'utf8' is not a supported encoding for the CharacterSet connection option.

And this is my doctrine.yaml file:

doctrine:
dbal:
    url: '%env(resolve:DATABASE_URL)%'
    driver: 'sqlsrv'
    server_version: '2017'
    # IMPORTANT: You MUST configure your server version,
    # either here or in the DATABASE_URL env var (see .env file)
    charset: 'cp1254'
orm:
    auto_generate_proxy_classes: true
    naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
    auto_mapping: true
    mappings:
        App:
            is_bundle: false
            dir: '%kernel.project_dir%/src/Entity'
            prefix: 'AppEntity'
            alias: App

I am using MSSQL 2017 with my Symfony application and sqlsrv driver. I did not understand the reason I get the error and I will be happy if someone can find the problem. Thanks!

2

Answers


  1. Chosen as BEST ANSWER

    Ok I have found the problem. The problem that I was triyng to update .env file but in my local I was supposed to update .env.local. It is working now.


  2. First, I advise you to be careful that the DATABASE_URL environment variable doesn’t override the charset you have configured. (Sometimes, there is something like this line:

    DATABASE_URL=sqlsrv://app:[email protected]:32781/app?charset=utf8
    

    Then, according to the configuration reference, charset option is RDBMS specific, developers have to refer to the manual of their RDBMS for more information.

    According to this answer the charset utf8 doesn’t exist, but the charset UTF-8.

    So, try to be sure that the syntax cp1254 is existing. (I see some things more complex like SQL_Latin1_General_CP1254_CI_AS, but this is perhaps collation, not charset)

    IMO and according to the error message, your problem is related to my first suggestion because your charset config seems to be ignored.

    If your parameter is still ignored, try to remove url parameter in your doctrine.yaml file and temporally use something without the env variables.

    doctrine:
        dbal:
            default_connection:           default
            connections:
                default:
                    dbname:               db_name
                    host:                 localhost
                    port:                 3000
                    user:                 foo
                    charset:              'CP1254'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search