The forum will experience an outage sometime between February 10 at 7:00pm EST and February 12 at 11:59 EST for installation of security updates. The actual time and duration of the outage are unknown but attempts will be made to minimize the downtime. We apologize for any inconvenience.

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 05 Nov '12, 05:36

MMacdonald's gravatar image

MMacdonald
1766617
accept rate: 0%

edited 15 Mar '13, 21:07

Mark%20Culp's gravatar image

Mark Culp
22.3k9129262


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...

permanent link

answered 05 Nov '12, 06:08

Volker%20Barth's gravatar image

Volker Barth
29.3k287438644
accept rate: 32%

edited 05 Nov '12, 06:50

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

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

Your link to connection parameters seems broken - 404?

(05 Nov '12, 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...

(05 Nov '12, 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.

(05 Nov '12, 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:)

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

Thanks, I've corrected that.

(05 Nov '12, 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();
}

?>
permanent link

answered 05 Nov '12, 06:47

MMacdonald's gravatar image

MMacdonald
1766617
accept rate: 0%

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.

permanent link

answered 06 Nov '12, 10:10

Ian%20McHardy's gravatar image

Ian McHardy
2.6k22945
accept rate: 39%

Your answer
toggle preview

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: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×123
×122
×46

question asked: 05 Nov '12, 05:36

question was seen: 6,726 times

last updated: 15 Mar '13, 21:07