How to connect to named instance with ODBC Driver 17 on PHP 7?

Multi tool use
Multi tool use





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I am trying to connect to an MS SQL database that is a named instance from my linux box running PHP 7.1. I am using ODBC Driver 17 for SQL Server.



I have successfully installed the ODBC driver from Microsoft and successfully connected to databases that are not named instances. For the named instance, I have tried every combination that I can think of (with/without port, quotes, brackets, etc.)



//$host = 'mySVR-SQL'; // THIS WORKS
//$host = '10.10.10.12345'; // THIS ALSO WORKS
$host = "SERVINSTANCE_NAME"; // THIS DOES NOT WORK
$host = "SERVINSTANCE_NAME,1433"; // THIS DOES NOT WORK
$host = "[SERVINSTANCE_NAME]"; // THIS DOES NOT WORK
$host = '123.12.34.56INSTANCE_NAME'; // THIS DOES NOT WORK
$user = 'my_username';
$pass = 'my_password';
$db = 'my_database';

$conn = "odbc:DRIVER={ODBC Driver 17 for SQL Server};SERVER=$host;DATABASE=$db";

$db_c = new PDO($conn, $user, $pass);

//connection string without variables for troubleshooting
$db_c = new PDO("odbc:Driver={ODBC Driver 17 for SQL Server};Server=123.12.34.56INSTANCE_NAME;Database=MyDatabase", "my_username", "my_password");


This is the error message I get:



SQLSTATE[HYT00] SQLDriverConnect: 0 [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired


What can I do to further troubleshoot this issue? Note that I was able to connect fine before using pdo_dblib drivers on php 5.6. But since we are upgrading to PHP 7, I figured we should use the microsoft drivers (which work fine, except for the named instance.)



This DOES work (using dblib):



$db_c = new PDO("dblib:host=123.12.34.56INSTANCE_NAME;dbname=MyDatabase;charset=utf8", "my_username", "my_password");









share|improve this question

























  • If it is listen on port 1433, then it isn't named instance, but a default instance. Also, the part after the slash is the instance name, not the database name. Do not specify port for named instances, unless it is configured to not use dynamic ports. Simply provide host name in format SERVER_NAMEINSTANCE_NAME.

    – Andrey Nikolov
    Jan 4 at 7:09











  • Yes, I am using the instance name after the slash, not the database name, I've updated my question with the correct syntax. I've removed the port and tested but it is still not finding the server.

    – MrB
    Jan 4 at 14:39











  • Note that SERVER_NAME must be the DNS-resolvable hostname or IP address, not the Windows hostname. Note also that you must remove PORT=1433; from your $conn = line.

    – TallTed
    Jan 4 at 14:49











  • Yes. I can ping the server_name from the linux box I am trying to connect from, but I also tried the connection with the IP address in place of the server name - still get the same error. I removed PORT=1433. I've updated the question with the revised connection string, sans port.

    – MrB
    Jan 4 at 15:08











  • any update? I have the same problem

    – celsowm
    Feb 11 at 21:47


















1















I am trying to connect to an MS SQL database that is a named instance from my linux box running PHP 7.1. I am using ODBC Driver 17 for SQL Server.



I have successfully installed the ODBC driver from Microsoft and successfully connected to databases that are not named instances. For the named instance, I have tried every combination that I can think of (with/without port, quotes, brackets, etc.)



//$host = 'mySVR-SQL'; // THIS WORKS
//$host = '10.10.10.12345'; // THIS ALSO WORKS
$host = "SERVINSTANCE_NAME"; // THIS DOES NOT WORK
$host = "SERVINSTANCE_NAME,1433"; // THIS DOES NOT WORK
$host = "[SERVINSTANCE_NAME]"; // THIS DOES NOT WORK
$host = '123.12.34.56INSTANCE_NAME'; // THIS DOES NOT WORK
$user = 'my_username';
$pass = 'my_password';
$db = 'my_database';

$conn = "odbc:DRIVER={ODBC Driver 17 for SQL Server};SERVER=$host;DATABASE=$db";

$db_c = new PDO($conn, $user, $pass);

//connection string without variables for troubleshooting
$db_c = new PDO("odbc:Driver={ODBC Driver 17 for SQL Server};Server=123.12.34.56INSTANCE_NAME;Database=MyDatabase", "my_username", "my_password");


This is the error message I get:



SQLSTATE[HYT00] SQLDriverConnect: 0 [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired


What can I do to further troubleshoot this issue? Note that I was able to connect fine before using pdo_dblib drivers on php 5.6. But since we are upgrading to PHP 7, I figured we should use the microsoft drivers (which work fine, except for the named instance.)



This DOES work (using dblib):



$db_c = new PDO("dblib:host=123.12.34.56INSTANCE_NAME;dbname=MyDatabase;charset=utf8", "my_username", "my_password");









share|improve this question

























  • If it is listen on port 1433, then it isn't named instance, but a default instance. Also, the part after the slash is the instance name, not the database name. Do not specify port for named instances, unless it is configured to not use dynamic ports. Simply provide host name in format SERVER_NAMEINSTANCE_NAME.

    – Andrey Nikolov
    Jan 4 at 7:09











  • Yes, I am using the instance name after the slash, not the database name, I've updated my question with the correct syntax. I've removed the port and tested but it is still not finding the server.

    – MrB
    Jan 4 at 14:39











  • Note that SERVER_NAME must be the DNS-resolvable hostname or IP address, not the Windows hostname. Note also that you must remove PORT=1433; from your $conn = line.

    – TallTed
    Jan 4 at 14:49











  • Yes. I can ping the server_name from the linux box I am trying to connect from, but I also tried the connection with the IP address in place of the server name - still get the same error. I removed PORT=1433. I've updated the question with the revised connection string, sans port.

    – MrB
    Jan 4 at 15:08











  • any update? I have the same problem

    – celsowm
    Feb 11 at 21:47














1












1








1








I am trying to connect to an MS SQL database that is a named instance from my linux box running PHP 7.1. I am using ODBC Driver 17 for SQL Server.



I have successfully installed the ODBC driver from Microsoft and successfully connected to databases that are not named instances. For the named instance, I have tried every combination that I can think of (with/without port, quotes, brackets, etc.)



//$host = 'mySVR-SQL'; // THIS WORKS
//$host = '10.10.10.12345'; // THIS ALSO WORKS
$host = "SERVINSTANCE_NAME"; // THIS DOES NOT WORK
$host = "SERVINSTANCE_NAME,1433"; // THIS DOES NOT WORK
$host = "[SERVINSTANCE_NAME]"; // THIS DOES NOT WORK
$host = '123.12.34.56INSTANCE_NAME'; // THIS DOES NOT WORK
$user = 'my_username';
$pass = 'my_password';
$db = 'my_database';

$conn = "odbc:DRIVER={ODBC Driver 17 for SQL Server};SERVER=$host;DATABASE=$db";

$db_c = new PDO($conn, $user, $pass);

//connection string without variables for troubleshooting
$db_c = new PDO("odbc:Driver={ODBC Driver 17 for SQL Server};Server=123.12.34.56INSTANCE_NAME;Database=MyDatabase", "my_username", "my_password");


This is the error message I get:



SQLSTATE[HYT00] SQLDriverConnect: 0 [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired


What can I do to further troubleshoot this issue? Note that I was able to connect fine before using pdo_dblib drivers on php 5.6. But since we are upgrading to PHP 7, I figured we should use the microsoft drivers (which work fine, except for the named instance.)



This DOES work (using dblib):



$db_c = new PDO("dblib:host=123.12.34.56INSTANCE_NAME;dbname=MyDatabase;charset=utf8", "my_username", "my_password");









share|improve this question
















I am trying to connect to an MS SQL database that is a named instance from my linux box running PHP 7.1. I am using ODBC Driver 17 for SQL Server.



I have successfully installed the ODBC driver from Microsoft and successfully connected to databases that are not named instances. For the named instance, I have tried every combination that I can think of (with/without port, quotes, brackets, etc.)



//$host = 'mySVR-SQL'; // THIS WORKS
//$host = '10.10.10.12345'; // THIS ALSO WORKS
$host = "SERVINSTANCE_NAME"; // THIS DOES NOT WORK
$host = "SERVINSTANCE_NAME,1433"; // THIS DOES NOT WORK
$host = "[SERVINSTANCE_NAME]"; // THIS DOES NOT WORK
$host = '123.12.34.56INSTANCE_NAME'; // THIS DOES NOT WORK
$user = 'my_username';
$pass = 'my_password';
$db = 'my_database';

$conn = "odbc:DRIVER={ODBC Driver 17 for SQL Server};SERVER=$host;DATABASE=$db";

$db_c = new PDO($conn, $user, $pass);

//connection string without variables for troubleshooting
$db_c = new PDO("odbc:Driver={ODBC Driver 17 for SQL Server};Server=123.12.34.56INSTANCE_NAME;Database=MyDatabase", "my_username", "my_password");


This is the error message I get:



SQLSTATE[HYT00] SQLDriverConnect: 0 [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired


What can I do to further troubleshoot this issue? Note that I was able to connect fine before using pdo_dblib drivers on php 5.6. But since we are upgrading to PHP 7, I figured we should use the microsoft drivers (which work fine, except for the named instance.)



This DOES work (using dblib):



$db_c = new PDO("dblib:host=123.12.34.56INSTANCE_NAME;dbname=MyDatabase;charset=utf8", "my_username", "my_password");






sql-server odbc php-7.1






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 18:29







MrB

















asked Jan 3 at 21:25









MrBMrB

163




163













  • If it is listen on port 1433, then it isn't named instance, but a default instance. Also, the part after the slash is the instance name, not the database name. Do not specify port for named instances, unless it is configured to not use dynamic ports. Simply provide host name in format SERVER_NAMEINSTANCE_NAME.

    – Andrey Nikolov
    Jan 4 at 7:09











  • Yes, I am using the instance name after the slash, not the database name, I've updated my question with the correct syntax. I've removed the port and tested but it is still not finding the server.

    – MrB
    Jan 4 at 14:39











  • Note that SERVER_NAME must be the DNS-resolvable hostname or IP address, not the Windows hostname. Note also that you must remove PORT=1433; from your $conn = line.

    – TallTed
    Jan 4 at 14:49











  • Yes. I can ping the server_name from the linux box I am trying to connect from, but I also tried the connection with the IP address in place of the server name - still get the same error. I removed PORT=1433. I've updated the question with the revised connection string, sans port.

    – MrB
    Jan 4 at 15:08











  • any update? I have the same problem

    – celsowm
    Feb 11 at 21:47



















  • If it is listen on port 1433, then it isn't named instance, but a default instance. Also, the part after the slash is the instance name, not the database name. Do not specify port for named instances, unless it is configured to not use dynamic ports. Simply provide host name in format SERVER_NAMEINSTANCE_NAME.

    – Andrey Nikolov
    Jan 4 at 7:09











  • Yes, I am using the instance name after the slash, not the database name, I've updated my question with the correct syntax. I've removed the port and tested but it is still not finding the server.

    – MrB
    Jan 4 at 14:39











  • Note that SERVER_NAME must be the DNS-resolvable hostname or IP address, not the Windows hostname. Note also that you must remove PORT=1433; from your $conn = line.

    – TallTed
    Jan 4 at 14:49











  • Yes. I can ping the server_name from the linux box I am trying to connect from, but I also tried the connection with the IP address in place of the server name - still get the same error. I removed PORT=1433. I've updated the question with the revised connection string, sans port.

    – MrB
    Jan 4 at 15:08











  • any update? I have the same problem

    – celsowm
    Feb 11 at 21:47

















If it is listen on port 1433, then it isn't named instance, but a default instance. Also, the part after the slash is the instance name, not the database name. Do not specify port for named instances, unless it is configured to not use dynamic ports. Simply provide host name in format SERVER_NAMEINSTANCE_NAME.

– Andrey Nikolov
Jan 4 at 7:09





If it is listen on port 1433, then it isn't named instance, but a default instance. Also, the part after the slash is the instance name, not the database name. Do not specify port for named instances, unless it is configured to not use dynamic ports. Simply provide host name in format SERVER_NAMEINSTANCE_NAME.

– Andrey Nikolov
Jan 4 at 7:09













Yes, I am using the instance name after the slash, not the database name, I've updated my question with the correct syntax. I've removed the port and tested but it is still not finding the server.

– MrB
Jan 4 at 14:39





Yes, I am using the instance name after the slash, not the database name, I've updated my question with the correct syntax. I've removed the port and tested but it is still not finding the server.

– MrB
Jan 4 at 14:39













Note that SERVER_NAME must be the DNS-resolvable hostname or IP address, not the Windows hostname. Note also that you must remove PORT=1433; from your $conn = line.

– TallTed
Jan 4 at 14:49





Note that SERVER_NAME must be the DNS-resolvable hostname or IP address, not the Windows hostname. Note also that you must remove PORT=1433; from your $conn = line.

– TallTed
Jan 4 at 14:49













Yes. I can ping the server_name from the linux box I am trying to connect from, but I also tried the connection with the IP address in place of the server name - still get the same error. I removed PORT=1433. I've updated the question with the revised connection string, sans port.

– MrB
Jan 4 at 15:08





Yes. I can ping the server_name from the linux box I am trying to connect from, but I also tried the connection with the IP address in place of the server name - still get the same error. I removed PORT=1433. I've updated the question with the revised connection string, sans port.

– MrB
Jan 4 at 15:08













any update? I have the same problem

– celsowm
Feb 11 at 21:47





any update? I have the same problem

– celsowm
Feb 11 at 21:47












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030009%2fhow-to-connect-to-named-instance-with-odbc-driver-17-on-php-7%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030009%2fhow-to-connect-to-named-instance-with-odbc-driver-17-on-php-7%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







2aKBme,POTOwSJTzc,XvrnhVz8Ai81eCXg0z8hkp86QbhqLO1ddXxlVh MYF,LzAgMwj6,Ol,WnQf9
yf9FXjeRtKow4,J5vIZz9I DX

Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas