6

My doctrine repository code doesn't work, while I am able to access the database and read table data normally.

I get this stacktrace:

EntityManager->getRepository('AppBundle:Person') in src\AppBundle\Controller\PersonViewController.php (line 18) 

  public function indexAction(Request $request) {
         $em = $this->getDoctrine()->getManager();
         $repo = $em->getRepository('AppBundle:Person');
         $persons = $repo->findAll();
         dump($persons);

The person entity model:

Person.php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Class Person
 * @Package AppBundle/Entity
 *
 * @ORM\Entity(repositoryClass="AppBundle\Repository\PersonRepository")
 * @ORM\Table(name="[Person]")
 */
class Person {
    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=4)
     */
    protected $type;
}

In case this is necessary as well, the repo code:

PersonRepository.php

<?php

namespace AppBundle\Repository;

use /** @noinspection PhpUndefinedClassInspection */
    Doctrine\ORM\EntityRepository;

class PersonRepository extends EntityRepository {

    public function create() {
        $entity = new Person();
        $entity->type('WM_B');
        $this->_em->persist($entity);
        $this->_em->flush();
    }
}
rmsluimers
  • 663
  • 2
  • 11
  • 21

2 Answers2

27

Sql Server Configuration Manager -> Sql Server Network Configuration -> Protocols For -> TCP/IP ->

I changed the following

IpAll
TCP Dynamic Ports 49226
TCP Port

To:

IpAll
TCP Dynamic Ports
TCP Port          1433

Not sure what TCP Dynamic Ports are and why they were configured.

rmsluimers
  • 663
  • 2
  • 11
  • 21
3

For SQL Server 2019 Developer

In default installation:

  • TCP/IP is disabled
  • Authentication is set to Windows Authentication mode only

The Fix

  1. To enable TCP/IP:

    Start Menu
     -> Microsoft SQL Server 2019
     -> SQL Server 2019 Configuration Manager 
     -> SQL Server Network Configuration 
     -> Protocols For MSSQLSERVER 
     -> TCP/IP
     -> Enable
    
  2. To enable SQL Authentication mode:

     Start Menu
     -> Microsoft SQL Server Tools 
     -> Microsoft SQL Server Management Studio
     -> Right-Click the server node 
     -> Properties
     -> Security
     -> Under Authentication choose "SQL Server and Windows Authentication Mode"
    
  1. The above changes needs restarting the "MSSQLSERVER" service.
Shadi Alnamrouti
  • 11,796
  • 4
  • 56
  • 54