JDBC Connection Permission Denied on Android

Odpovědět JDBC Connection Permission Denied on Android

  • 3. dubna 2012 12:35
     
      Obsahuje kód

    I'm new to Android, and Java altogether for that matter and I'm having a heck of a time trying to connect my Android app to SQL Server 2005. I'm aware that the preferred way of dealing with data is via the consumption of a web service, but for my purposes I'm opting to connect via a direct SQL Connection. That said, I added the JDBC4 jar file to my project, and ensured that port 1433 was open on my sql server (I tested this using a windows desktop app as well as a windows mobile app I had handy), but for the life of me can't seem to get my android app to connect do to a permissions denied error:

    com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host
    10.0.0.217, 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."
    .

    I'm using my sa username/password, which again I tested on a different platform, so I know conceptually at least, it should work. The following is the connection code I have in Eclipse:

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
    con
    = DriverManager.getConnection("jdbc:sqlserver://10.0.0.217;databaseName=star","sa","MyPassword");

    Based on what I've been reading, everyone's solution was to add 1433 to their SQL configuration, but mine already is, and I also ensured the IP address was enabled (and I tested using both windows desktop and mobile apps to ensure it wasn't a security issue). I'm at a loss but hoping that someone had a similar issue that turned up a solution.

    Any help would be great,

    Aj


    If at first you don't succeed, skydiving is definitely not for you!


Všechny reakce

  • 3. dubna 2012 17:42
     
     
    Do you see an error logged with permission denied on SQL Server when you attempt to connect from your JDBC?  I have had to support JDBC to SQL, so I can't help you directly.  But I would confirm your SQL Server is evening seeing the connection.  You can look at ERRORLOG file if you have failed logins tracking, or you can open up SQL Server Profiler to see who is connecting to SQL Server.

    Mohit K. Gupta --- MCTS, MCITP, MCC2011
    My Blog OpsVault My MSDN Blog Twitter @SQLCAN

  • 3. dubna 2012 17:47
    Moderátor
     
     

    Hello,

    Are you sure of the 10.0.0217 address ?

    Have you tried to have a look at http://www.eclipse.org/forums/ ?

    Are you trying to connect a local or remote database ? Are you trying to connect from Android ( i hope you will excuse this question, but with my poor english, i am not sure to have understood your problem fully )

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

  • 3. dubna 2012 17:52
     
     
    Do you see an error logged with permission denied on SQL Server when you attempt to connect from your JDBC?  I have had to support JDBC to SQL, so I can't help you directly.  But I would confirm your SQL Server is evening seeing the connection.  You can look at ERRORLOG file if you have failed logins tracking, or you can open up SQL Server Profiler to see who is connecting to SQL Server.

    Mohit K. Gupta --- MCTS, MCITP, MCC2011
    My Blog OpsVault My MSDN Blog Twitter @SQLCAN

    Hey Mohit,

    Good find...the error turned out to be a lack of permission in the Android manifest file.  Apparently the program must be given permissions via XML to itself to open sockets in order to communicate directly via TCP/IP.  I however after the fact ran into an issue with JDBC using SSL in a way where I was not able to facilitate it.  I've since switched to using the JTDS driver and have had a great deal of success.

    Thank you for your input,

    Aj


    If at first you don't succeed, skydiving is definitely not for you!

  • 3. dubna 2012 17:54
     
     

    Hello,

    Are you sure of the 10.0.0217 address ?

    Have you tried to have a look at http://www.eclipse.org/forums/ ?

    Are you trying to connect a local or remote database ? Are you trying to connect from Android ( i hope you will excuse this question, but with my poor english, i am not sure to have understood your problem fully )

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    Hey Papy Normand,

    I am sure about the address, it actually turns out that it's an Android issue more than it is a JDBC issue...well more or less.  It's not particularly well documented, but you need to change the Android manifest file to allow internet communication, ie. TCP/IP.  As I mentioned to Mohit, I've decided to use the JTDS driver as it has less stringent requirements in terms of SSL, and thus allowed me to get up and running.

    Thank you for your input,

    Aj


    If at first you don't succeed, skydiving is definitely not for you!

  • 3. dubna 2012 17:59
     
     Odpovědět Obsahuje kód

    In case anyone else happens across this post, the resolution was to add the following code to the manifest:

    <uses-permission android:name="android.permission.INTERNET"/>

    By doing so it allows the android app to open sockets to communicate via TCP/IP.  Any errors other than that will require a different solution.

    Hope it helps,

    Aj


    If at first you don't succeed, skydiving is definitely not for you!

  • 19. dubna 2012 21:44
    Moderátor
     
     Odpovědět
    The Microsoft JDBC Driver is not yet supported on the Android platform.  You may want to raise your issue with Google to determine if there is an issue with the way they process SSL secured login packets.

    Microsoft JDBC Driver Product Team