C Sharper
C Sharper

Reputation: 8646

Error in connecting to SQLServer Error regarding TCP

I am connecting my android app to sqlserver through following code:

String url="jdbc:sqlserver://10.0.2.2;instance=14GRAFICALI\\MSSQLSERVER2008;databaseName=AndroidDB;integratedsecurity=true";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        TextView tvData=(TextView)findViewById(R.id.tvSelectedData);

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
            Connection conn =DriverManager.getConnection(url);                   

            Statement statement=conn.createStatement();
            ResultSet resultSet=statement.executeQuery("select * from UserMaster");
            while(resultSet.next()){
                tvData.setText(" Data1 : "+resultSet.getString(1)+"  Data 2 : "+resultSet.getNString(2));
            }

        } catch (Exception e) {
            e.printStackTrace();
            tvData.setText(e.getMessage());
        }

Error:

The TCP/IP connection to the host 10.0.2.2, port 1433 has failed.

I am not understanding why this problem is happening.

Logcat:

09-07 10:41:36.343: W/System.err(344): com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 10.0.2.2, port 1433 has failed. Error: "Permission denied. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

In configuration manager i have also enbled TCP/IP protocol.

enter image description here

Please guid me.

Upvotes: 1

Views: 219

Answers (1)

Tourki
Tourki

Reputation: 1774

You probably forgot to add the INTERNET permission in your Android Manifest

Upvotes: 3

Related Questions