Hi i was trying to connect to remote data base .bt it is showing error
as "Sending error Connection to http://localhost:53541 refused" can
any one help me plz here is my code

var curWindow = Titanium.UI.currentWindow;
var loginURL = "http://localhost/LoginPage/";;
var scrollView = Titanium.UI.createScrollView({
  contentWidth:'auto',
  contentHeight:'auto',
  top:0,
  showVerticalScrollIndicator:true,
  showHorizontalScrollIndicator:true
});
var view = Titanium.UI.createView({
  width:"100%",
  height: "auto",
  top:10,
  paddingBottom: 15
});
var conn = true;
if (Titanium.Network.networkType === Titanium.Network.NETWORK_NONE) {
    conn = false;
}

var lbl_User = Titanium.UI.createLabel({
  text:'Username:',
  height:30,
  width:"98%",
  color:'#222',
  font: {fontSize:16},
  top: 10
});
// Username
var username = Ti.UI.createTextField({
    color:'#336699',
    top:10,
    left:90,
    width:300,
    height:40,
    hintText:'Username',
    keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
    returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});


var lbl_Pass = Titanium.UI.createLabel({
  text:'Password:',
  height:30,
  width:"98%",
  color:'#222',
  font:{fontSize:16},
  top: 90
});
// Password
var password = Ti.UI.createTextField({
     color:'#336699',
    top:90,
    left:90,
    width:300,
    height:40,
    hintText:'Password',
    passwordMask:true,
    keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
    returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});


// Login button
var loginBtn = Ti.UI.createButton({
    title:'Login',
    top:220,
    width:90,
    height:35,
    borderRadius:1,
    font:{
        fontFamily:'Arial',
        fontWeight:'bold',
        fontSize:14
    }
});

var loginReq = Titanium.Network.createHTTPClient();
loginBtn.addEventListener('click',function(e){
        if(conn){
        if(username.value !== '' && password.value != '')
        {
                loginReq.open("POST", "http://localhost:53541/WebSite1/
Default.aspx");
                loginReq.setRequestHeader("content-type", "application/json");
var param = {};
param.uname = username.value;
param.pwd = password.value;
Ti.API.info('params'+JSON.stringify(param));
loginReq.send(JSON.stringify(param));

        }
        else
        {
                 alert("All fields are required");
        }
        }
        else
        {
                 alert("A connection to the internet is required!");
        }

});


loginReq.onload = function(){
   Ti.API.info('RAW ='+this.responseText);
 if(this.status == '200'){
    Ti.API.info('got my response, http status code ' + this.status);
    if(this.readyState == 4){
      var response=JSON.parse(this.responseText);
      Ti.API.info('Response = '+response);
    }else{
      alert('HTTP Ready State != 4');
    }
 }else{
    alert('HTTp Error Response Status Code = '+this.status);
    Ti.API.error("Error =>"+this.response);
 }


};

loginReq.onerror = function() {
    Ti.API.error(this.status + ' - ' + this.statusText);

};
view.add(lbl_User);
view.add(username);
view.add(lbl_Pass);
view.add(password);
view.add(loginBtn);
scrollView.add(view);

curWindow.add(scrollView);

here is my Default.aspx.cs code
 protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection cnn = new SqlConnection("Data Source=ITS-BA-DC02\
\MSSQL2008_SAND;Initial Catalog=TestDB_Chaitanya;User
Id=sa;Password=01Explore");
        cnn.Open();
        string name;
        string email;
        int result = 0;
        string uname = Request.Form["username"];
        string pwd = Request.Form["password"];
        SqlCommand cmd = new SqlCommand("select * from users where
username='" + uname + "' and password='" + pwd + "'", cnn);
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr != null && dr.HasRows == true)
        {
            name = dr["name"].ToString();
            email = dr["email"].ToString();
            result = 1;

        }
        else
        {
            result = 0;


        }
        dr.Close();
        cnn.Close();

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to