SQLSTATE[08001]:[Microsoft][ODBC Driver 13 for SQL Server]TCP 提供程序:无法建立连接,因为目标计算机主动拒绝它

问题描述 投票:0回答:3

我的学说存储库代码不起作用,而我能够正常访问数据库并读取表数据。

我得到这个堆栈跟踪:

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);

人实体模型:

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;
}

如果这也是必要的,存储库代码:

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();
    }
}
php symfony doctrine-orm
3个回答
27
投票

Sql Server 配置管理器 -> Sql Server 网络配置 -> 协议 -> TCP/IP ->

我更改了以下内容

IpAll
TCP Dynamic Ports 49226
TCP Port

致:

IpAll
TCP Dynamic Ports
TCP Port          1433

不确定 TCP 动态端口是什么以及为什么配置它们。


3
投票

对于 SQL Server 2019 开发人员

默认安装:

  • TCP/IP 已禁用
  • 身份验证仅设置为 Windows 身份验证模式

修复

  1. 启用 TCP/IP:

    Start Menu
     -> Microsoft SQL Server 2019
     -> SQL Server 2019 Configuration Manager 
     -> SQL Server Network Configuration 
     -> Protocols For MSSQLSERVER 
     -> TCP/IP
     -> Enable
    
  2. 启用 SQL 身份验证模式:

     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. 上述更改需要重新启动“MSSQLSERVER”服务。

0
投票

SQLSTATE[08001]:[Microsoft][ODBC Driver 17 for SQL Server]TCP 提供程序:无法建立连接,因为目标计算机主动拒绝它。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.