Laravel-SQLSTATE [HY001]无法分配足够的内存-MsSQL [英] Laravel - SQLSTATE[HY001] Unable to allocate sufficient memory - MsSQL

查看:136
本文介绍了Laravel-SQLSTATE [HY001]无法分配足够的内存-MsSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MsSql数据库中的视图在laravel中建立我的项目的第二个连接,我正确配置了.env和config,但这是内存溢出的错误:

I'm making a second connection of my project in laravel with a view in an MsSql database, I configured my .env and config correctly, however this is an error of memory overflow:

$ php artisan tinker
Psy Shell v0.10.5 (PHP 7.3.24-3+ubuntu18.04.1+deb.sury.org+1 — cli) by Justin Hileman
>>> use App\Condinvest\BoletoPropCondominio as BPC
>>> BPC::first();
Illuminate\Database\QueryException with message 'SQLSTATE[HY001] Unable to allocate sufficient memory (meudominio.com.br:5000) (severity 8) (SQL: select top 1 * from [View_Boleto_Prop_Condominio])'
>>> 

已经在我的php.ini中进行了更改:

already changed in my php.ini:

memory_limit = 128M

但错误仍然存​​在.

我的模型简要如下:

BaseView.php

BaseView.php

<?php
    
namespace App\Condinvest;

use Illuminate\Database\Eloquent\Model;

class BaseView extends Model
{
    protected $connection = 'condinvest';
}

BoletoPropCondominio.php

BoletoPropCondominio.php

<?php

namespace App\Condinvest;

class BoletoPropCondominio extends BaseView
{
    protected $table = 'View_Boleto_Prop_Condominio';

    protected $fillable = [
        'Id_Condo_lan',
        ...
        'Id_titular'
    ];
}

当我直接通过命令终端执行相同的查询时:

when I do the same query directly through the command terminal:

SELECT TOP 1 * FROM View_Boleto_Prop_Condominio;

成功返回我的数据.

请问有人可以告诉我发生了什么事,或者如何更好地调试以了解错误的出处.

Can anyone tell me what may be happening, or how I can debug better to understand where the error is, please.

编辑

>>> DB::connection('condinvest')->getConfig()['driver']
=> "sqlsrv"

推荐答案

由于错误显然是由数据库进程(而非php进程)报告的,因此我期望更改内存限制在php.ini中起作用.

Since the error is apparently being reported by the database process (not the php process), I would not expect changes to memory limits in php.ini to have any effect.

我发现了此问题,其中提到了在使用过时的驱动程序和MSSQL服务器.要检查Laravel使用的是哪个驱动程序,请在Tinker控制台中键入 DB :: connection()-> getConfig()['driver'] .如果看到 sqlsrv ,则此处一切正常,但是,如果看到 dblib ,则可能是错误的根源.此问题据说已在Laravel 5.7中已修复,如果有多个驱动程序,则更喜欢受支持的驱动可用,但您的 database.php 配置文件也可能使用了错误的文件.

I found this issue which mentions this specific error when using a deprecated driver with MSSQL Server. To check which driver Laravel is using, type DB::connection()->getConfig()['driver'] into your Tinker console. If you see sqlsrv then everything is ok here, but if you see dblib then this might be the source of the error. This problem was supposedly fixed in Laravel 5.7 to prefer the supported drivers if more than one is available, but it's also possible that your database.php config file uses the wrong one.

也有可能实际上超出了数据库服务器或其所在系统的内存限制.能够在命令提示符下运行查询而不会出现错误提示这不是 情况,但仍然值得研究.如果可用内存非常低,则可能无法同时运行php和数据库查询.只要数据库进程与终端在同一台计算机上运行,​​就可以通过在终端中运行 free -h 命令来检查可用的系统内存.但是,如果您使用共享主机提供商,则数据库可能位于单独的计算机上.

It is also possible that the memory limits of the database server or the system it resides on are actually being exceeded. Being able to run the query in a command prompt without getting the error suggests that this is not the case, but it may still be worth investigating. If the available memory is very low then it's possible that there is not enough to run both php and the database query at the same time. You can check the available system memory by running the free -h command in the terminal, as long as the database process is running on the same machine as your terminal. However, if you are using a shared hosting provider then it is possible that the database is on a separate machine.

这篇关于Laravel-SQLSTATE [HY001]无法分配足够的内存-MsSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆