cancel
Showing results for 
Search instead for 
Did you mean: 

Open Client Interface connection to SQL Anywhere

Former Member
2,661

Hi all, I'm using Open Client API's to connect to the database server. Connection to the server using ct_connect is successful. But I have more than one database running for same database server. I'm not able find any connection property to set the database name to connect to (using ct_con_props function). Is there a way to specify the database name to connect to using ct_connect ?

Thanks Girish

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member

Chris' comment above is correct. Unlike ASE, SQL Anywhere does not have the concept of logging into a master database and then having the client send a USE statement to switch databases. Hence, SQL Anywhere needs to use the information available within the login packet to determine which database the client wants to connect to. The server therefore keys in on the service name which is in the login packet and uses that name as the database that the client wants to connect to. This service name information is only used in cases where the server is running multiple databases. For servers that are only running one SQL Anywhere database, the server assumes the client wants to connect to the single database that is running on the server regardless of what is specified as the service name in the login packet. Hence, if you are running multiple databases on the same SQL Anywhere server and need to connect using either Open Client or jConnect, then specify the name of the database that you need to connect to as the service name during the connect attempt and you should be good to go.

chris_keating
Product and Topic Expert
Product and Topic Expert

IIRC you would require separate entries in the interfaces file for each of the databases configured on the SQLA server. You would then connect to the name defined in the interfaces file for the desired database to establish the connection.

For example,

dbsrvx.exe -n DbServerName -x tcpip sqla_db_1.db -n db1 sqla_db_2.db -n db2

The interfaces file would have entries similar to:

[db1] query=NLWNSCK,<ip>,<port> master=NLWNSCK,<ip>,<port>

[db2] query=NLWNSCK,<ip>,<port> master=NLWNSCK,,<ip>,<port>

where [db1] and [db2] are the database names hosted by the SQLA engine. Make sure that you specify the <ip> and <port> values to reflect the environment on which the server is configured.

Former Member
0 Kudos

Thanks a lot Chris and Karim. I'll configure interface file and try connecting to individual databases using Open Client Interface. I'll update the outcome.

Thanks Girish

Former Member

Created a separate entry in interface file for each database running on SQL Anywhere server. Used 'database name'(service name) in place of 'server name' while initiating connection to server using ct_connect.Connection to the specified database was successful.

Thanks a lot for the detailed explanation and resolution to the problem.