Support » Developing with WordPress » Connecting to an external SQL Server database

  • I am trying to make a connection with a SQL Server. I am using the snippets plugin to add custom code.

    $serverName = ",1433"; 
    	$connectionInfo = array( "Database"=>"databaseName", "UID"=>"username", "PWD"=>"password");
    	try {
    		$conn = sqlsrv_connect($serverName, $connectionInfo);
    	} catch (Exception $e) {
    		echo '<script>console.log("Caught exception: '.  $e->getMessage(). '");</script>';
    if( $conn ) {
    		echo "Connection established.<br />";
    		echo "Connection could not be established.<br />";
    		die( print_r( sqlsrv_errors(), true ) );

    I have all the drivers installed and i am able to connect to the same database with the same credentials with MS SQL Studio. However when i attempt the connection from wordpress i just get this error:

    [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. 
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.