Search code examples
javasql-server-2012oledblinked-server

How to specify the url connection string to a Linked Server?


I am trying to connect from a Java application to a Linked Server I created with MSSQL Server (called OLEDBSOURCE below). Can someone please help me get the connection string / url right?

db.url=jdbc:sqlserver://myipaddress:1433;databaseName=OLEDBSOURCE;

Below is a screenshot of SQL Server Management Studio. You can see where the Linked Servers section is, it's different than the databases... so how does the connection url need to be?

enter image description here


Solution

  • If it helps anyone else:

    The URL string itself was the same, minus the database name: db.url=jdbc:sqlserver://:1433;

    For the query string however, I had to use OPENQUERY format:

                createSQLQuery("SELECT value "
                        + "FROM OPENQUERY(OLEDBSOURCE,'SELECT value "
                        + "FROM tablename ORDER BY value')")