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.
 

OliverA

Expert
Licensed User
Longtime User
VB.net in which you can see it connects just fine, is there something stupid im missing here ?
Your server is bendanisoftware.com
Your instance is CORTSENDB
Your database is LoginDB
For jTDS, this would amount to a connection string of
B4X:
jdbc:jtds:sqlserver://bandanisoftware.com/LoginDB;instance=CORTSENDB
A good source for jTDS configuration information: http://jtds.sourceforge.net/faq.html
 
Upvote 0

Past11

Member
Hi Oliver.
Thank you very much, i will try that adn thanks to all of your for helping out, even stupid can be improved 😂
Hi again Oliver.

Thank to you i finally got a connection using the SQLtest app so now i can finally start implementing it into my own app thank you all so much for your time and effort to help on the right path you are great souls thank you :)
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
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.
I wrote this a while back...
https://www.b4x.com/android/forum/threads/how-to-connect-to-sql-server-using-jtds-1-3-1-jar.111446/#post-737031
I have customers still using it.
 
Upvote 0

Albert Kallal

Active Member
Licensed User
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 ?

that was me. I not really sure I should jump in this thread. However, your vb.net connection works because I assume you are on the SAME network as the server. But you using a server name - you cannot do that in B4A with a direct connect, because your android does not have windows networking, and you can't thus use a server name, but must use IP address. So, just because your android is connected to the same network (not phone data connection), but a known local LAN connection, then even then, there is no computer name resolution available. You have to use IP address. You can no more see a list of network computers, or see computer names - that requires a windows networking stack and system. You don't have that. So, assuming that your phone is valid and connected to the same network. (not outside connection), then that sample should work fine. But anything you connect to on that network will require IP address, since no windows networking name resolution is available. So, I would first use SSMS and not even vb or any other code. If you can connect by IP address, then the sample I have should work just fine.

So, say if SSMS running on wi-fi from a laptop can connect to the database with IP address? Then the phone and that sample will also connect. If your same laptop on the same wi-fi with SSMS studio can't connect, then your phone will not either.

EDIT:
And where in your connection VB.net example do we see/find/have/use "MSSQL" what kind of GUESS was that?
Where???

Your tossing in MSSQL, yet you don't have that ANY place in your vb.net connection here.

You have this: servername\SQL INSTANCE NAME
And to be specific? What does the above mean?
It means this:

SERVER NAME = bendanisoftwarecom
DATABASE INSTANCE NAME = CORTSENDB

So, why are you typing in BOTH server name and database instance name for the server name?

You need:
SERVER NAME " BENDANISOFTWARE.com, but as I stated, you must use IP address.
And then you have for the database instance: MSQL? where did that come from?

In that connection box, you don't type in both server + server instance name. But, that should have been dead obvious since there is a box for the sql server instance name. Your vb.net connection string allows both sql server name + sql instance name to be combined for the server\SQL instance name.

However, to reduce confusing (and that when using jdbc to sql server, you do NOT include the sql instance in the server connect name. They are separate, and I did that on purpose in that connection tester to eliminate this confusing, but also to make it quite obvious that you ONLY enter the server name (and as noted, as a IP address).

And I am always short of time, but that connection tester was written to help you test without having to write any code.

And I been just too busy - not been around here for 3months. But I been meaning to extend that sql tester to scan the network for valid sql servers, but its at least a start. You should be able to just enter the server name (ip address), the sql instance and the other information and touch connect. However, do keep in mind that when using jdbc for SQL server, the database instance name is 100% separate from the server name - and that includes the connection string.

it goes without saying? You want to be aware of the difference between the server name, and WHAT a database instance is! Without this basic concept, then you keep entering the server + database instance for the server name when using jdbc, and all will be for not.

And as noted, anytime you do ANYTHING with android when connected to a local network? You don't have name resolution, and thus can't as a general rule connect to anything at all by name, but only by IP address.

Regards,
Albert D. Kallal
Edmonton, Alberta Canada
 
Last edited:
Upvote 0

Past11

Member
that was me. I not really sure I should jump in this thread. However, your vb.net connection works because I assume you are on the SAME network as the server. But you using a server name - you cannot do that in B4A with a direct connect, because your android does not have windows networking, and you can't thus use a server name, but must use IP address. So, just because your android is connected to the same network (not phone data connection), but a known local LAN connection, then even then, there is no computer name resolution available. You have to use IP address. You can no more see a list of network computers, or see computer names - that requires a windows networking stack and system. You don't have that. So, assuming that your phone is valid and connected to the same network. (not outside connection), then that sample should work fine. But anything you connect to on that network will require IP address, since no windows networking name resolution is available. So, I would first use SSMS and not even vb or any other code. If you can connect by IP address, then the sample I have should work just fine.

So, say if SSMS running on wi-fi from a laptop can connect to the database with IP address? Then the phone and that sample will also connect. If your same laptop on the same wi-fi with SSMS studio can't connect, then your phone will not either.

EDIT:
And where in your connection VB.net example do we see/find/have/use "MSSQL" what kind of GUESS was that?
Where???

Your tossing in MSSQL, yet you don't have that ANY place in your vb.net connection here.

You have this: servername\SQL INSTANCE NAME
And to be specific? What does the above mean?
It means this:

SERVER NAME = bendanisoftwarecom
DATABASE INSTANCE NAME = CORTSENDB

So, why are you typing in BOTH server name and database instance name for the server name?

You need:
SERVER NAME " BENDANISOFTWARE.com, but as I stated, you must use IP address.
And then you have for the database instance: MSQL? where did that come from?

In that connection box, you don't type in both server + server instance name. But, that should have been dead obvious since there is a box for the sql server instance name. Your vb.net connection string allows both sql server name + sql instance name to be combined for the server\SQL instance name.

However, to reduce confusing (and that when using jdbc to sql server, you do NOT include the sql instance in the server connect name. They are separate, and I did that on purpose in that connection tester to eliminate this confusing, but also to make it quite obvious that you ONLY enter the server name (and as noted, as a IP address).

And I am always short of time, but that connection tester was written to help you test without having to write any code.

And I been just too busy - not been around here for 3months. But I been meaning to extend that sql tester to scan the network for valid sql servers, but its at least a start. You should be able to just enter the server name (ip address), the sql instance and the other information and touch connect. However, do keep in mind that when using jdbc for SQL server, the database instance name is 100% separate from the server name - and that includes the connection string.

it goes without saying? You want to be aware of the difference between the server name, and WHAT a database instance is! Without this basic concept, then you keep entering the server + database instance for the server name when using jdbc, and all will be for not.

And as noted, anytime you do ANYTHING with android when connected to a local network? You don't have name resolution, and thus can't as a general rule connect to anything at all by name, but only by IP address.

Regards,
Albert D. Kallal
Edmonton, Alberta Canada

Hi Albert.

Thank you very much for your reply, i have not been online for about two weeks so im sorry for my late reply :) indeed your application helped me, and one of the other post that completely showed me how the string was built up, then i finally understood the syntax of connection string, which was my missing part, i absolutely loved your connection tester, and i still use it now when doing MSSQL database work. so thank you very much :) and thank you for your reply everything is working fine now :) have a nice day :)
 
Upvote 0
Top