In order to post questions, answers, or comments, you now need a validated email address. Details on how to validate your address are in the FAQ.

I'm attempting to use the PHP PDO ODBC driver to connect to a SQL Anywhere Database:

<?php

$host = "EnergyManagementDev";
$db = "EnergyManagementDev";
$user = "dba";
$pass = "sql";

try 
{
$db = new PDO("odbc:Driver={SQL Anywhere 12};Server={$host};Database={$db};Uid={$user};Pwd={$pass};LOG=C:\MyClient.Log", $user, $pass);
    $db = null; //close the connections
}
catch(PDOException $e)
{
    echo $e->getMessage();
}

?>

The ODBC Data Source Administrator screen captures are below ("Test Connection" is successful):

ODBC Data Source Administrator screen capture 1

ODBC Data Source Administrator screen capture 2

But I get the following error:

SQLSTATE[08001] SQLDriverConnect: -100 [Sybase][ODBC Driver][SQL Anywhere]Database server not found

The log output from C:MyClient.Log is:

12:21:53 Attempting to connect using:
UID=dba;PWD=********;DBN=EnergyManagementDev;ServerName=EnergyManagementDev;CON=SQL_DBC_40c8a90;LOG=C:\MyClient.Log
12:21:53 Attempting to connect to a running server...
12:21:53 Trying to start SharedMemory link ...
12:21:53     SharedMemory link started successfully
12:21:53 Attempting SharedMemory connection (no sasrv.ini cached address)
12:21:53 No named shared memory buffer found
12:21:53 Not attempting to autostart server
12:21:53 Cannot connect to server

What am I doing wrong?

asked Nov 05 '12 at 05:36

MMacdonald's gravatar image

MMacdonald
1766617

edited Mar 15 '13 at 21:07

Mark%20Culp's gravatar image

Mark Culp
18.2k9109212


I guess the connection is missing the information to connect to a network server (assuming that your client and the database engine are running on different machines). It seems that your PDO connection string supports the usual SQL Anywhere connection parameters, so you could add

  • ";HOST=192.168.1.10" or
  • ";LINKS=TCPIP" (possibly with further protocol options)

to your connection string.

Both parameters will express that you want to connect over TCP/IP instead just locally.

For further diagnostis, you could also add ";LOG=C:MyClient.Log" - that should create a text file with messages, how the client library tries to find and (hopefully) connect to the database...

answered Nov 05 '12 at 06:08

Volker%20Barth's gravatar image

Volker Barth
22.2k220331480

edited Nov 05 '12 at 06:50

Thanks Volker. I've edited the question to add the log output as suggested.

(Nov 05 '12 at 06:28) MMacdonald
Replies hidden

Your link to connection parameters seems broken - 404?

(Nov 05 '12 at 06:29) MMacdonald
Replies hidden

Apparently, the client just tries to connect locally via shared memory. Have you tried my suggestions - they should exactly solve the problem, i.e. making the client to connect via TCP/IP...

(Nov 05 '12 at 06:30) Volker Barth

Thanks. It was only necessary to specify the host (in fact it didn't allow both to be specified - "The HOST and LINKS options cannot both be specified"). I'll post the working connection string to help future readers, and accept your answer.

(Nov 05 '12 at 06:45) MMacdonald
Replies hidden

You are correct: The "or" in my suggestion list is meant as an "exclusive or" - natural languages are so ambigiuous:)

(Nov 05 '12 at 06:48) Volker Barth

Thanks, I've corrected that.

(Nov 05 '12 at 06:51) Volker Barth
showing 3 of 6 show all flat view

Here is the working connection code after following the suggestions in Volker's answer.

<?php

$host = "EnergyManagementDev";
$db = "EnergyManagementDev";
$user = "dba";
$pass = "sql";

try 
{
    $db = new PDO("odbc:Driver={SQL Anywhere 12};Server={$host};Database={$db};Uid={$user};Pwd={$pass};Host=192.168.1.10", $user, $pass);
    $db = null; //close the connections
}
catch(PDOException $e)
{
    echo $e->getMessage();
}

?>

answered Nov 05 '12 at 06:47

MMacdonald's gravatar image

MMacdonald
1766617

If you wanted to store the connection information in the Data Source, you can do that. To use that, you would need to change your connection string provide the DSN, UID and PWD:

$db = new PDO("odbc:DSN=EnergyManagement;Uid={$user};Pwd={$pass}", $user, $pass);

This way, it would get the server name, database name and host information from the DSN. I haven't actually tried this from PHP, but it should work. There is a chance you will still need the Driver={SQL Anywhere 12} but I don't think you will.

answered Nov 06 '12 at 10:10

Ian%20McHardy's gravatar image

Ian McHardy
2.0k22236

Your answer
toggle preview

Are you providing an answer to the original question, or making a comment on the question or an answer? If you are making a comment please do not post a new answer. Click "Add new comment" on the question or answer instead. If you are responding to a previous comment, click on the "reply" icon (    ) for that comment.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link: [text](http://url.com/ "title")
  • image: ![alt text](/path/img.jpg "title")
  • numbered list (indent for sublists):
    1. Foo
    2. Bar
  • bullet list (indent for sublists):
    * Foo
    * Bar
  • to add a line break, add two spaces to where you would like the new line to be.
  • Code blocks should be indented by 4 spaces. SQL code should begin with ":::SQL" on the first line.
  • basic HTML tags are also supported

Tags:

×99
×97
×26

Asked: Nov 05 '12 at 05:36

Seen: 3,016 times

Last updated: Mar 15 '13 at 21:07

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link: [text](http://url.com/ "title")
  • image: ![alt text](/path/img.jpg "title")
  • numbered list (indent for sublists):
    1. Foo
    2. Bar
  • bullet list (indent for sublists):
    * Foo
    * Bar
  • to add a line break, add two spaces to where you would like the new line to be.
  • Code blocks should be indented by 4 spaces. SQL code should begin with ":::SQL" on the first line.
  • basic HTML tags are also supported