Unable to query linked server using JDBC driver

Narayana Chirravuri 1 Reputation point
2022-05-24T08:55:27.913+00:00

HI All ,

  I have created a linked server in Management studio. When I tried to to query linked server using JDBC driver then error got popped "**No login mappings exists**". But same thing working in Management studio.. The JDBC url I am using is 

jdbc:sqlserver://<Host>:1433;Databasename=Database11;selectMethod=cursor;authenticationScheme=NTLM;Domain=<Domain>;IntegratedSecurity=true

User name and password I have tried with Active directory credentials. Is there any possibility to pass login mappings through JDBC url.

Thanks in Advance,

SQL Server | Other
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Olaf Helper 47,441 Reputation points
    2022-05-24T09:48:26.417+00:00

    using JDBC driver

    JDBC is for Java applications; MS SQL Server isn't one.
    You have to use ODBC or OleDB instead; see Linked Servers (Database Engine)


  2. Erland Sommarskog 121.8K Reputation points MVP Volunteer Moderator
    2022-05-24T22:07:10.92+00:00

    The error message suggest that when you set up the linked server, you did not set up self-mapping, and then you only set up login mapping for some accounts.

    By default, when you create a linked server by saying:

    EXEC sp_addlinkedserver THATSERVEROVERTHERE
    

    You will get self-mapping. This means that users who are logged on the local server, will access THATSERVEROVERTHERE with the same credentials as they when logged in on the local server. This is also desirable, as there are no security issues here.

    However, this does not always work out for various reasons, for instance the users has no login on their own on the remote server. In that case you can set up login mapping, so that the access to the remote server is by a specific SQL login. This mapping can be setup for everyone (not good for security!) or only for specific users.

    The fact that you log on through JDBC has nothing to do with it as such. But it does not matter how the Java program log on.

    0 comments No comments

  3. YufeiShao-msft 7,146 Reputation points
    2022-05-25T02:51:35.64+00:00

    Hi @Narayana Chirravuri

    No Login-mapping Exists

    You can check SQL Server account you use, if it is not a valid login or you do not have permission, maybe you should provide this user in the connection string, such as:

    EXEC master.dbo.sp_addlinkedserver @server = N'ONE', @srvproduct=N'SQL', @provider=N'SQLNCLI11', @datasrc=N'SQLSERVER-1', @provstr=N'Data Source=SQLSERVER-1;User ID=user  
    

    https://blog.sqlauthority.com/2019/06/07/sql-server-fix-msg-7416-access-to-the-remote-server-is-denied-because-no-login-mapping-exists/

    Or if you do not want to map any logins with aspecific SQL Serve account, you can select the security context

    EXEC sp_addlinkedsrvlogin 'TEST1', 'false', 'userLocal', 'userRemote', 'remotePassword'  
    

    https://www.databasejournal.com/ms-sql/linked-severs-on-ms-sql-part-3/


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.