简体   繁体   中英

Unable to connect Android App to local MSSQL database

Hi I created a SQL management Database, I wish to connect to the Database through Android App

I am not what I did wrong, I am not able to login.

This my SQL management Studio 2012, My DataBase name I call it DB. 这是我的数据库截图

This is my SQL Server Configuration manager , what I did is I enable TCP/IP and shared memory. 在此处输入图片说明

And then I enable all the IP, and I set the ALL port to 1433, the dynamic port I leave it empty. 双击TCP / IP

在此处输入图片说明

I create the database using this username 在此处输入图片说明

This is what my code is like for my Android Java file, connection to database

     String driver = "net.sourceforge.jtds.jdbc.Driver";


     String connString = "jdbc:jtds:sqlserver://127.0.0.1:1433/db;encrypt=false;
user=username;password=1234;instance=SQLEXPRESS;";
        String username = "username";
        String password = "1234";
        int id;

Is it something wrong with my step, how come it is not connecting?

Connecting directly to a DB from android is highly discouraging. The primary reason is performance. See, it is really expensive to keep a remote connection alive than rather just call Web Services on demand which is more portable and also more secure.

Therefore, its better to develop a REST API instead for your service and invoke it from client android app or any other client for that matter.

Edit: For your current issue at hand, see if it works by replacing localhost IP to the real(assuming 192.168.0.16 is also ipa4 ip?) one.

String connString = "jdbc:jtds:sqlserver://192.168.0.16/db;encrypt=false;
user=username;password=1234;instance=SQLEXPRESS;";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM