How to fix PDO sqlsrv connection timeout in Laravel? - pdo

developer!
I'm using Laravel framework and I need to connect to MS SQL 2014 Express database. I've made all the proper configurations in .env (and I even tried tried to put connection parameters straight away to the database.php config) but on the first request i'm always getting timeouted with error:
PDOException in Connector.php line 55:
SQLSTATE[08001]: [Microsoft][ODBC Driver 11 for SQL Server]TCP Provider: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
After the timeout I always get this php fatal:
FatalErrorException in Connector.php line 55
Invalid handle returned.
As a dev tools I'm using XAMPP, and when I'm restarting apache server, sometimes I can establish connection successfully, but only in 1 out of 20-30 tries.
Laravel is using PDO driver, so i tried to use sqlsrv_connect() - and it worked! No errors, everything is fine.
Can somebody help me configure PDO to work? Laravel only uses PDO driver, so I can't just switch to sqlsrv_connect.

I had this problem running on my local machine. I restarted the laravel server and ensured that the ms sql localdb was running and the problem resolved it self.

I had the same error.
After removing the
host // DB_HOST entries from your .env-File and from your config/database.php it worked for me.

What I did for connection are
Installed the correct version of sqlsrv dlls.
Updated doctrine dbal package in Laravel.
My database configuration is below
'sqlsrv3' => [
'driver' => 'sqlsrv',
'host' => '<host-name>',
'database' => '<database-name>',
'username' => '<your-username>',
'password' => '<your-password>',
]

After one day of search in this problem, I found that the problem in DB_PORT, when pass port number 1433 the problem happen, so leave it empty, if you change it in .env, change it like this:
DB_CONNECTION=sqlsrv
DB_HOST=YourHostName
DB_PORT=
DB_DATABASE=YourDBName
DB_USERNAME=YourDBUser
DB_PASSWORD=YourDBPassword
DB_TRUST_SERVER_CERTIFICATE=true
Or if you change it on config/database.php, change it like this:
'sqlsrv' => [
// ...
'port' => env('DB_PORT', null), // <<<< see here
],
Try it :)

Had the same error, turns out it was my password that was wrong. Do confirm you have the right values.
DB_HOST={youservername}.database.windows.net
DB_DATABASE={dbname}
DB_USERNAME={username}
DB_PASSWORD={yourpassword}
DB_PORT=1433
If it doesn't fix do reset the password and try again

Related

Database proxy in karate

I am using karate framework for my API testing in our organization. I am able to execute my project in local where DB connections are successful, when i execute in cloud jenkins we are getting below error
Error : Failed to obtain JDBC Connection; nested exception is java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
DB class used: https://github.com/intuit/karate/blob/master/karate-demo/src/main/java/com/intuit/karate/demo/util/DbUtils.java
Do we have any option to set proxy for DB only, i have also gone through proxy setup in karate-config.js like karate.configure('proxy', { uri: 'http://my.proxy.host:8080', username: 'john', password: 'secret' ,nonProxyHosts:['http://example.com'] }. This is setting up proxy to my API and not for DB instance.
I am also trying to check whether my jenkins server firewall is blocking to create a connection to my db.
Any help from karate framework creators or implementer's?
whether my jenkins server firewall is blocking
That is most likely the case, nothing Karate (or anyone associated with it) can do here to help.
Also please read this: https://stackoverflow.com/a/52078427/143475

Localhost error code : 200 | Error in processing request (It seems like the connection to server has been lost.)

phpMyAdmin 7.3.11
XAMPP (Apache, MySQL:3306)
Browser : Opera
I imported the database from remote server to the local.
Everything is fine on the remote server but on the local server, I am receiving this server error with error code 200.
Error in processing request
Error code 200
Error text: Ok (rejected)
It seems that the connection to server has been lost.
Please check your network connectivity and server status.
In the local server, I am able to view all the database tables but I am not able to modify them.
On connecting the android app with local sever I am not able to fetch data from the local server.
Server Log
2019-12-04 17:17:56 0 [Note] InnoDB: Buffer pool(s) load completed at 191204 17:17:56
2019-12-04 17:18:08 11 [Warning] Access denied for user ''#'localhost' (using password: NO)
2019-12-04 17:18:08 13 [Warning] Access denied for user ''#'localhost' (using password: NO)
2019-12-04 17:18:08 15 [Warning] Access denied for user ''#'localhost' (using password: NO)
I followed this Symfony bug solution:
https://github.com/symfony/symfony/commit/8e34978e4e2c4bf7dac97e44e904368c4cfb54f8 and made the modification (add array_value) on usr/share/php/Symfony/Component/DependencyInjection/ContainerBuilder.php and everything work now!
Open the ContainerBuilder.php file in directory
"/usr/share/php/Symfony/Component/DependencyInjection/",
and change this line:
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
into this:
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs(array_values($arguments));
This is may be due to memory limit, try increasing memory limit.
I don't know what was the problemin your sql serve, but I changed memory_limit to -1 in php.ini file after restart your xampp serve. And now check the problem is fixed :)
I was using Opera browser, but it doesn't show any errors on Chrome and it is working fine now. Turns out the header content for finding the opera browser is missing in the Apache environment. So, the localhost/phpmyadmin will work fine on Chrome , safari and firefox.
Same problem here! I was using Chrome and I tried to open PhpMyAdmin in another browser (Firefox) and it was working correctly! All that I had to do was to reset all the settings of Chrome; "Settings>Advanced>System>Restore settings to their original defaults."
And after that everything was working properly!
(Edit: Before the solution I tried to change the memory limit but without success, and from what I know you should not change it to -1. This sets memory limit to infinity which is a high security risk.)
Check your cookies in your browser settings. if the cookies are blocked, then this type of issues comes. Allow all cookies and try again.
I have the exactly same problem on my firefox browser. I solved it immediately after clear site cookie and data.

Datasource not working in JBoss 7.2

When I create a datasource, a service restart is required to make it work, regardless of the method used to create it (standalone.xml, JBoss CLI, JBoss Administration Console). Attached is the procedure I have written for my team (exported from our Wiki space). The datasource gets created successfully, but when I test the connection, I get this:
From JBoss Administration Console
Unknown error
Unexpected HTTP response: 500
Request
{
"address" => [
("subsystem" => "datasources"),
("data-source" => "dsMyApp")
],
"operation" => "test-connection-in-pool"
}
Response
Internal Server Error
{
"outcome" => "failed",
"failure-description" => "JBAS010440: failed to invoke operation: JBAS010442: failed to match pool. Check JndiName: java:/dsMyApp",
"rolled-back" => true,
"response-headers" => {"process-state" => "reload-required"}
}
From JBoss CLI
JBAS010440: failed to invoke operation: JBAS010442: failed to match pool. Check JndiName: java:/dsMyApp
If I restart the JBoss server, the datasource works fine (server, port, username and password are all correct).
Any thoughts?
Thank you
The Quick Answer: YES, restarting makes a reload and then activates the datasource
I suggest you doing a reload with jboss-cli (It´s the quickest way)
I´ve created all my datasources with jboss-cli and I always need to
perform this action to allow them to work. After the reload, the datasource connection can be tested.
/opt/wildfly/bin/jboss-cli.sh --connect --controller=192.168.119.116:9990 --commands="reload --host=master"
Hope it helps

ZF2 project not working on virtual host

I have a project which is in zf2.
It runs properly on all other systems other than mine.I have checked the virtual host is running properly for other projects on my system.
when I hit xyx.loc it redirects properly but when I hit xyz.loc/user it gives error
An error occurred
An error occurred during execution; please try again
later.
Though I have enable error reporting.
I am not able to figure out whether its apache error or php error or zf2 error or something else.
The project uses ZF\Apigility
The same folder works on other systems very well.
This is the default error template message. ZF2 is catching any exceptions and hiding them from you due to the configuration settings.
Ensure you have the following configuration.
'view_manager' => [
'display_not_found_reason' => true,
'display_exceptions' => true,
],

Phirehose Setup Problems

Trying to use the Phirehose class from https://github.com/fennb/phirehose
After uploading everything to the server, when i try to run sample.php i get the following errors. I've tried to manually run through the code but can't get to the bottom of this one. Any help would be greatly appreciated...
Phirehose: Connecting to twitter stream: http://stream.twitter.com/1/statuses/sample.json with params: array ( 'delimited' => 'length',)
Phirehose: Resolved host stream.twitter.com to 199.59.148.138
Phirehose: Connecting to 199.59.148.138
Phirehose: Connection established to 199.59.148.138
Phirehose: HTTP failure 1 of 20 connecting to stream: HTTP ERROR : (). Sleeping for 10 seconds.
So, there are multiple different versions of the script. The .zip availble for phirehose in githubs download section is a different version than just copying down the most recent version of the script.
Most recent version of the script appears to work perfectly.