Site icon Alaska Prevention

Android App unable to access Azure database

My android application is supposed to get data from an Azure SQL database, but the queries keep responding with “Reference to database and/or server name is not supported in this version of SQL Server”.

On the server side audit log it just states “Reference to database and/or server name in ‘delivery.dbo.upload’ is not supported in this version of SQL Server”

Code:

public class CheckDeliveries extends AsyncTask<String, String, String> {

        String z = "";
        Boolean isSuccess = false;
        private ArrayList<ModelU> arrayList;


        //@Override
        protected void onPostExecute(String r) {
            if (z == "ok") {
                GetDeliveries adapter = new GetDeliveries(ViewUpcoming.this, arrayList);
                mRecyclerView.setAdapter(adapter);
            }
            Context context = getApplicationContext();
            CharSequence text = "2 " + z;
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }

        @Override
        protected String doInBackground(String... strings)
        {
            try
            {
                con = connectionclass();
                if (con == null)
                {
                    z = "Internet Issue";
                }
                else
                {
                    String query = "SELECT * FROM [delivery].[dbo].[upload]";
                    Statement stmt = con.createStatement();
                    ResultSet rs = stmt.executeQuery(query);
                    z = "ok";

                    if(rs.next()) {
                        do {
                            @SuppressLint("Range") ModelU modelu = new ModelU(
                                    "" + rs.getInt(rs.getInt("ID")),
                                    "" + rs.getString(rs.getInt("Name")),
                                    "" + rs.getString(rs.getInt("Address")),
                                    "" + rs.getString(rs.getInt("Status"))
                            );
                            arrayList.add(modelu);
                        }
                        while (rs.next());
                    }
                    else {
                        z = "Invalid Query";
                        isSuccess = false;
                    }
                }
            } catch (Exception ex) {
                isSuccess = false;
                z = ex.getMessage();
            }

            return z;
        }
    }

    @SuppressLint("NewApi")
    public Connection connectionclass() {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        Connection connection = null;
        String ConnectionURL = null;
        try {
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
            ConnectionURL = "jdbc:jtds:sqlserver://2033051.database.windows.net:1433;database=delivery;user=XXXXXXXX;password=XXXXXXXX;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;ssl=request;loginTimeout=30;";
            connection = DriverManager.getConnection(ConnectionURL);
        }
        catch (SQLException se)
        {
            Log.e("error 1", se.getMessage());
        }
        catch (ClassNotFoundException e)
        {
            Log.e("error 2", e.getMessage());
        }
        catch (Exception e)
        {
            Log.e("error 3", e.getMessage());
        }
        return connection;
    }
} 

Toastbox output

Azure database

Any help is greatly appreciated!

Exit mobile version