I can't connect to azure sql server with my android app.

DENİZ ARLI 1 Reputation point
2021-09-10T21:12:52.967+00:00

I can't connect to azure sql server with my android app. I'm using jtds jar for connecting to sql server but I can't. Android studio giving this error: "E/Error is: Login failed for user 'sharkman'." How can I connect to my sql server?

Azure SQL Database
{count} votes

2 answers

Sort by: Most helpful
  1. Alberto Morillo 34,671 Reputation points MVP Volunteer Moderator
    2021-09-10T22:40:10.117+00:00

    Please make sure are trying to get connected correctly. Try something like below:

    try {
    
        String SQL = "select * from dbo.Student";
    
        Class.forName("net.sourceforge.jtds.jdbc.Driver");
        String url = String.format("jdbc:jtds:sqlserver://***.database.windows.net:1433/<your database name>;user=***;password=***;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;");
        conn = DriverManager.getConnection(url);
    
        stmt = conn.createStatement();
        rs = stmt.executeQuery(SQL);
    
        while (rs.next()) {
            System.out.println(rs.getString("name"));
        }
        close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    

    I hope this YouTube video helps you go through all the steps.


  2. Alberto Morillo 34,671 Reputation points MVP Volunteer Moderator
    2021-09-11T00:10:53.597+00:00

    Let me know if this article (example) works for you.


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.