Can you connect an Android Xamarin App, to sql server directly or is it necessary to consume some WebApi or some other way?

0

I'm starting in the mobile app, and I have an App that needs to bring all the data from sql server "online", I tried to connect the App to the sql server as if it were a WinForm, and when it is connected to the PC the test smartphone and start debugging, correctly select, insert, update, etc, but when I disconnect it from the pc, and open the App, I want to make a select, and does not do the App, as if it does not was connecting to SQL, is there any different way to connect the App to SQL Server? Here I have an example that I have in the App about a login that I made, and that works for me only when the test smartphone is connected to the PC

 ConexionController con = new ConexionController();
        cTripleDES decry = new cTripleDES();
        SqlConnection miConexion =new SqlConnection( "data source = snare.arvixe.com; initial catalog=logins; user id=******; password= ******");
        public int Login(string user, string password)
        {
            try
            {   
                if (miConexion.State == ConnectionState.Closed)
                {
                    miConexion.Open();
                }
                SqlCommand comando = new SqlCommand("select email, clave from CrmCustomers where email = '" + user + "'and clave = '" + password + "' ", miConexion);
                comando.ExecuteNonQuery();
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(comando);
                da.Fill(ds, "CrmCustomers");
                DataRow DR;
                DR = ds.Tables["CrmCustomers"].Rows[0];
                if ((user == DR["email"].ToString()) && (password == DR["clave"].ToString()))
                {
                    miConexion.Close();
                    return 1;
                }
                else
                {
                    miConexion.Close();
                    return 2;
                }

            }
            catch (Exception ex)
            {
                miConexion.Close();
                return 3;
            }
        }
    
asked by Oscar Navarro 19.09.2017 в 00:17
source

1 answer

1

I think that you would make a webservice, it is safer and better to use it with volley, anyway, you should be able to do it without problems, have you checked the user's persms in the database? since the connection is allowed? what database engine is it? Did you check the external connection of the server? that is authorized external access to the base?

    
answered by 19.09.2017 / 01:48
source