DEV Community

Cover image for Setting up a Laravel project with SQL Server AND XAMPP / WAMP on Windows

Setting up a Laravel project with SQL Server AND XAMPP / WAMP on Windows

Odunayo Ogungbure on August 16, 2019

I spent a large part of yesterday trying to connect an existing Laravel project to MsSQL. I made some mistakes and used different tutorials but I f...
Collapse
 
maygallegos profile image
maygallegos • Edited

Hola, me marca un error

Illuminate\Database\QueryException : SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]Proveedor de TCP: No se puede establecer una conexión ya que el equipo de destino denegó expresamente dicha conexión.
(SQL: select * from sysobjects where type = 'U' and name = migrations)

at C:\xampp\htdocs\admin-lte-example\vendor\laravel\framework\src\Illuminate\Database\Connection.php:669
665| // If an exception occurs when attempting to run a query, we'll format the error
666| // message to include the bindings with SQL, which will make this exception a
667| // lot more helpful to the developer instead of just the database's errors.
668| catch (Exception $e) {

669| throw new QueryException(
670| $query, $this->prepareBindings($bindings), $e
671| );
672| }
673|

Exception trace:

1 PDOException::("SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]Proveedor de TCP: No se puede establecer una conexión ya que el equipo de destino denegó expresamente dicha conexión.
")
C:\xampp\htdocs\admin-lte-example\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

2 PDO::__construct("sqlsrv:Server=127.0.0.1,1433;Database=laravel", "userSQL", "passSQL", [])
C:\xampp\htdocs\admin-lte-example\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

Please use the argument -v to see more details.

Collapse
 
tylerjusfly profile image
Tyler

do you mind help taking a look, i had this error

Illuminate\Database\QueryException

could not find driver (SQL: select * from information_schema.tables where table_schema = forge and table_name = migrations and table_type = 'BASE TABLE')

at C:\Users\User\Documents\tiidelab\mds_backend\morningsc\manager-master\vendor\laravel\framework\src\Illuminate\Database\Connection.php:712
708▕ // If an exception occurs when attempting to run a query, we'll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database's errors.
711▕ catch (Exception $e) {
➜ 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e
714▕ );
715▕ }
716▕ }

1 C:\Users\User\Documents\tiidelab\mds_backend\morningsc\manager-master\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDOException::("could not find driver")

2 C:\Users\User\Documents\tiidelab\mds_backend\morningsc\manager-master\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct()
Bugsnag Warning: Couldn't notify. cURL error 60: SSL certificate problem: unable to get local issuer certificate (see curl.haxx.se/libcurl/c/libcurl-err...
) for notify.bugsnag.com

Collapse
 
ziscore profile image
Shailendra

This worked like a charm! Thanks a lot!

Collapse
 
rjalvarez profile image
Rafael Alvarez

729/5000
Hello, nice to greet you, I have a system made in Laravel 6 (migrated from Laravel 4) and MySQL but I must also connect it with SQL Server, there I only have to use a stored procedure to store some records in another system, as I should make the call from the controller? I have used the following but all give error
DB :: connection ('sqlsrv') -> SELECT ('SET NOCOUNT ON; CALL SP_APIRserve Service2?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ? ', $ arrangement);
and
DB :: connection ('sqlsrv') -> insert ('SET NOCOUNT ON; EXECUTE SP_APIRserve Service2?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ? ', $ arrangement);
and
DB :: connection ('sqlsrv') -> insert ('EXECUTE SP_APIRserveService2?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?', $ arrangement);
my email rjalvarez85@gmail.com

Collapse
 
mr_steelze profile image
Odunayo Ogungbure

I think what you have to do is

DB::connection()->statement()
Collapse
 
ediri_aghwotu profile image
Aghwotu Ovuoke

Thank you so much. This really helped me.

Collapse
 
mr_steelze profile image
Odunayo Ogungbure

Glad it did 🤗

Collapse
 
demabio profile image
Demabio

This came in so handy Sholley.Many thanks

Collapse
 
mr_steelze profile image
Odunayo Ogungbure

🥰

Collapse
 
endersonfs profile image
Endersonfs • Edited

I need help, i have this error.

PHP Warning: Module "pdo_sqlsrv" is already loaded in Unknown on line 0

Warning: Module "pdo_sqlsrv" is already loaded in Unknown on line 0

Illuminate\Database\QueryException

SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it.
(SQL: select * from sys.sysobjects where id = object_id(migrations) and xtype in ('U', 'V'))

at C:\Users\ender\OneDrive\Documents\laravel con sql server\projectapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:712
708▕ // If an exception occurs when attempting to run a query, we'll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database's errors.
711▕ catch (Exception $e) {
➜ 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e
714▕ );
715▕ }
716▕ }

1 C:\Users\ender\OneDrive\Documents\laravel con sql server\projectapp\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDOException::("SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it.
")

2 C:\Users\ender\OneDrive\Documents\laravel con sql server\projectapp\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct("sqlsrv:Server=localhost,1433;Database=coindev", "coindev", "coindev@2022.34", [])

Collapse
 
cokasio profile image
cokasio

Awesome! Thank you!

Collapse
 
dheeraj270693 profile image
dheeraj270693

Any help for Mamp, how to use the php_pdo_sqlsrv_7x_ts.dll and php_sqlsrv_7x_ts.dll file.