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 ?
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.
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.
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.
answered 20 Aug '13, 10:24