Android Question Please help with example code...

Past11

Member
Hi guys!
first off, this i brilliant software i think great work i have been doing A LOT of searching installing different drivers, following links and tutorials and so on. NOTHING WORKS.

The problem:

I have a MS SQL database on a friends server, i want to connect my android app to the database, BUT... as mentioned, i have installed several drivers for this but all the time new errors
could a friendly soul PLEASE provide a sample code that will allow me to connect directly to the database, without b4J Middleware, i normally would program in visual studio vb.net and there it is super easy to connect using the data sources manager, but here.... omg i am definetly missing something i cant get it to connect, any help would be greatly appreciated thank you by the way, i am totally new to mobile app developing, so please bear over with me on this one
Kind regards Kim.
 

Unobtainius

Active Member
Licensed User
Longtime User
I'm quite new to this myself but have like you have a lot of knowledge connecting to datasources in vb.net
For me I found the easiest solution was to build a web page (ASP.net or PHP) and have it hosted on the machine with the database on it (well the db doesn't even have to be on the same machine) because we know how to connect via ASP or PHP to a local or remote database, just call the web page with a few parameters (rather than raw sql statements), then have the page a display a JSON string containing the data you asked for. You then read that with OKHTTP2 (there are tons of examples on that)
Hope that helps
 
Upvote 0

Past11

Member
Hello.
Thank you so much for your reply, i had thought about doing something like that, however i am puzzled that it is so hard to connect to an online db here, surely there must be something simpler, i cant get wrap my little head around it....
 
Upvote 0

Unobtainius

Active Member
Licensed User
Longtime User
I like the the web approach because it puts a layer between the application and the database.
In my case it was for our company use and the access to the database was locked down to our company's Public IP Address on the database server
Once we went mobile we couldn't necessarily guarantee what IP address our mobile devices would be allocated
So having them communicate with the web site, only the web sites IP had to be added to database server machine's allowed IP list.
Also because of the way the web page is called (a bunch of parameters for Insert, select, delete, update) even if someone stumbles on the page, its very difficult to get it to return data or update the database in any way.
 
Upvote 0

Past11

Member
it definetly sounds like a good approach, doing it that way, however for theese initial testings of different things in app developement, i would like things as minimal as possible, to get a good and basic understanding of how the different processes works, "for me a steap learning curve here" so im looking for the very basic create a connection string to my database, and interact, then i will implement the security layer later, but i still cant get this damn thing to work, even with Erels solution, it is me who is dumb, i know but i just dont see the logic behind it right now....
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
i have been doing A LOT of searching installing different drivers, following links and tutorials and so on. NOTHING WORKS.
Which links? What code? What error messages?
however i am puzzled that it is so hard to connect to an online db here,
Why? Android is not a Desktop environment, and desktop drivers may not work (especially newer ones) with Android. I've ranted about this before. Please see this thread (it also points to a solution): https://www.b4x.com/android/forum/threads/mssql-jdbc-minimalistic-example.90548/post-573443. Other links with tips: https://www.b4x.com/android/forum/threads/mssql-jdbc-minimalistic-example.90548/#post-591195 and https://www.b4x.com/android/forum/threads/mssql-jdbc-minimalistic-example.90548/#post-573074
 
Upvote 0

Past11

Member
Hi OliverA.
Thank you so much for your reply i will take a look at the examples.... i have tried different examples from this site, JRDC2 etc. i cant remeber them, but have tried tons of different JDBC or SQL MYSQL MSSQL and so on i think i have tried more than 10 different at this point nothing works, obviously it is me who doesnt understand the examples, therefore i was asking for an example of the simplest code possible to connect directly to a MS SQL database online, i am sorry for not fully understand this yet, i will get it ....eventually i hope ? Errror..... ALOT.... the last errro im getting is. "com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure"
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
com.mysql.jdbc
This <> MSSQL.
JRDC2 etc. i cant remeber them, but have tried tons of different JDBC or SQL MYSQL MSSQL and so on i think i have tried more than 10 different at this point nothing works,
You need to slow down a bit and first we need to know what you are connection to! At first it is MSSQL, but now you switched to MYSQL. Each can have their own quirks on Android. jRDC2 is a totally other beast and there should have been zero driver issues. This thread has seemingly become a mess, so I suggest you settle down on one DB platform (MySQL, MSSQL, etc) and one particular driver for that DB platform. Try it and if you fail, open another thread with information on
1) what database are you trying to connect to
2) where that database is located (same network, online, etc)
3) how are you connecting to the DB (direct via JdbcSQL or indirectly via jRDC2)
4) the JDBC driver used
5) the code used in attempting to connect to the DB
6) Any error messages associated with the code
 
Upvote 0

Past11

Member
Hi Oliver.
sorry for the lack of info, here is the information i can give you.

1. i am trying to connect to a MS SQL database created with MICROSOFT SQL SERVER MANAGEMENT STUDIO
2. My database is located on a friends online server
3. I would love to connect the database directly from my phone app directly to the database without any "middleware"
4. JDBC driver used ... this is where i have tried them all i think Microsoft JDBC - Mysql JDBC - JDBC SERVER i think i really cant remember them all, i tried many different but nothing works, and again i know it all comes down to the code element, i am easily able to connect to a database saved on the phone, but not online, and that is what i want the simplest way to do that.
5. simple connection -

sql1.Initialize2("net.sourceforge.jtds.jdbc.Driver", "jdbc:jtds:sqlserver://bendanisoftware.com\CORTSENDB,"Username","Password")

I havent got much knowledge at this point so i cant give you much more info, than what i need is the simplest way to connect my app to the database on the server
thank you
 
Upvote 0

Unobtainius

Active Member
Licensed User
Longtime User
One quick question. Using vb.net can you connect your friends data remotely without any issues?
 
Upvote 0

Past11

Member
Develop web API which return JSON response which is 1 of the ways you can bypass a common issue which is firewall or access block by remote server due to security.

Hi Aeric.
Thank you for your reply, i will probably end up doing something like that if neccesary, right now i think i am all down to the syntax of the code to write to connect the database, so i havent even reached any problems with firewall or connection issues yet, but thank you
 
Upvote 0

Past11

Member
Hi Guys.
Found an b4a app that was made to test connection to database, and this program CANNOT connect to the database either, i have attached photo from the app with information, and also from VB.net in which you can see it connects just fine, is there something stupid im missing here ?
 

Attachments

  • SQL.TEST.jpg
    239.3 KB · Views: 220
  • SuccessLoginVB.net.PNG
    25.3 KB · Views: 233
  • vb.net stringto connect.PNG
    3.3 KB · Views: 215
Upvote 0

Past11

Member
Hi Erel i dont disagree with you you problably knows this better than anyone, my original question was if someone could provide a sample code to connect to a MS SQL database the absolutely easiest way, since i could not get it to work, " probably codewise" i have tried and followed your tutorial with JRCD2 and middleware but could not get it to work, i have tried many wrong things connecting directly but it will not create a connection, and the last effort was downloading that app, that should test connection, but it wont work in B4a, i cant provide any code since all i know with this program so far is the code provided in thoose examples, i am stronger in vb.net sprry for the probably newbie dumb questions.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Maybe this could be useful to you:


(and please, use a title's thread more clear)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…