1

Here is my situation. I have an application (Mirth Connect) running on the same server as SQL Anywhere 11. There is also another server on the same network running SQL Anywhere 11. I need to connect to both of them. They are both using the same SQL Anywhere "Server Name".

I need to use a JDBC connection to connect to either of them at any given moment. I can connect to the local instance just fine.

I tried to set up an ODBC connection to the remote server. When I test the connection it says it is all good. Then when I try to run a query I notice I am connected to the local server. It must be because both SQL Anywhere servers are using the same "Server Name".

How do I force the ODBC connection to connect to the Remote server?

Thank you!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Please provide the code you're using to connect to the servers. Chances are you need to be clever about the location you're connecting to; at the least two servers should resolve to two different ip:port combinations. – Nathaniel Ford May 01 '12 at 00:41

1 Answers1

0

You need to specify the IP address (and port, if not using the default) in the connection string. Your connection string must contain the LINKS parameter, with (at least) the following options:

LINKS=tcpip(HOST=<remote IP address>;PORT=<remote port>;DoBroadcast=None)

If the remote server is using the default port number, 2638, you don't need to specify the port number in the connection string. DoBroadcast=None tells the client library that it should make a direct connection to that host. The default (for version 11 and older) is to broadcast on the network looking for that server name, and whichever server responds first wins. Since there is a server on the local machine, it is very likely to respond first.

For version 12 and up, you can replace the entire LINKS parameter with the new HOST parameter:

HOST=<remote IP address>:<remote port>

which will have the same behaviour as the LINKS parameter above.

P.S. It is recommended that you give each server a unique server name, thus avoiding the need to hard-code the IP address of the host. Not to mention that you must be using some trickery to fool the second server into either (a) thinking its name is unique, or (b) not checking to see if it's unique, which it does by default. If you use unique server names, you don't need this extra stuff.

Disclaimer: I work for Sybase in SQL Anywhere engineering.

Graeme Perrow
  • 56,086
  • 21
  • 82
  • 121
  • Ok I added the LINKS and the ENG flags to the connection string. Now it is connecting to the local database, not the database on the server specified in the "Links Section". Here is the connection string I am using now. dbConn = DatabaseConnectionFactory.createDatabaseConnection( 'ianywhere.ml.jdbcodbc.jdbc3.IDriver', 'jdbc:ianywhere:Driver=SQL Anywhere 11;Eng=Bass;uid=dba;pwd=*;LINKS=tcpip(HOST=192.192.11.11;PORT=12345)' Why is it still looking at the local server? Also, I do not have control over the naming of the services. I am just the lucky guy who has to connect to these things :). – Garrett Fletcher May 02 '12 at 18:52
  • Also does the SQL Anywhere 11 driver let you connect directly to the database file with the DBF string? I have tried that too, but I do not have full access to the share yet. I have requested full access to the share. – Garrett Fletcher May 02 '12 at 19:24
  • Aha - you're using v11. If you upgrade to v12, you would be fine, but v11 and older had slightly different behaviour with respect to the HOST option. Will update my answer. – Graeme Perrow May 02 '12 at 22:47
  • You are brilliant! That did the trick. I had to tweak it a little, though. Instead of DoBroadcast=None I had to use DoBroadcast=Direct. I guess this is because of the way the server is broadcasting the server name? I found an article about DoBroadcast here: http://dcx.sybase.com/1200/en/dbadmin/dobroadcast-network-conparm.html Here is my final connection string: var dbConn = DatabaseConnectionFactory.createDatabaseConnection('ianywhere.ml.jdbcodbc.jdbc3.IDriver','jdbc:ianywhere:Driver=SQL Anywhere 11;uid=dba;pwd=*;Eng=VP_2;LINKS=tcpip(HOST=192.168.1.110;PORT=49193;DoBroadcast=Direct)'); – Garrett Fletcher May 03 '12 at 16:34
  • This is the part of the string that will probably be useful to anyone else reading this post: 'jdbc:ianywhere:Driver=SQL Anywhere 11;uid=dba;pwd=*;Eng=VP_2;LINKS=tcpip(HOST=192.168.1.110;PORT=49193;DoBroadcast=Direct)' – Garrett Fletcher May 03 '12 at 16:34