Android Tutorial Remote Database Connector (RDC) - Connect to any remote DB

Status
Not open for further replies.

tufanv

Expert
Licensed User
Longtime User
how do we send insert command to remote database after everything is done
 

stingrae

Member
Licensed User
Longtime User
Hi, when you say
does that mean I have to put a file on the server of where the SQL Database lives? I don't actually host my own webserver so I don't know if I am able to just do this or not.
Can you please clarify?
Thanks.
 

Douglas Farias

Expert
Licensed User
Longtime User
RemoteServer is running (Wed Jun 25 09:45:01 BRT 2014)
Connection successful.

ok
now how can i conect in the db with navicat
what i use
ip
id
pass

from
config.properties ?
i want to see all tables i have etc etc how can i?
 

Douglas Farias

Expert
Licensed User
Longtime User
This, is a visual part of your db
i need only to know how to conect on 1.jpg

for exemple
when i install de xamp

i can conect with localhost id=root pass=
and navicat conect on this

navicat u can conect to any db and see edit tables make changes
remote or local

same of phpmyadmin
 

Attachments

  • 1.jpg
    240.9 KB · Views: 376
  • 2.jpg
    247.2 KB · Views: 400
  • 3.jpg
    255.5 KB · Views: 403
  • 4.jpg
    244.5 KB · Views: 401

MrKim

Well-Known Member
Licensed User
Longtime User
Sigh, after four hours of monkey and typewriter work I finally got the sourceforge Java SQL Driver to work. I noticed a lot of posts struggling with this so I thought I would share a little of what I learned
This is what worked for me.
B4X:
DriverClass=net.sourceforge.jtds.jdbc.Driver
JdbcUrl=jdbc:jtds:sqlserver://127.5.5.1:49959/AndroidTest
User=skdata
Password=shopkeeper
A real key: Open the SQL server error log and look at what is failing. If you do not see a failed login then you aren't even getting to the server.
127.0.0.1 DID NOT WORK. I don't know why other than that it gave me this error in the SQL server log:
B4X:
Logon,Unknown,Login failed for user 'skdata'. Reason: Login-based server access validation failed with an infrastructure error. Check for previous errors. [CLIENT: 127.0.0.1]
I also received this error:
.
B4X:
Logon,Unknown,Could not connect because the maximum number of '1' dedicated administrator connections already exists. Before a new connection can be made<c/> the existing dedicated administrator connection must be dropped<c/> either by logging off or ending the process. [CLIENT: 127.0.0.1]
I believe the difference was the PORT I was using. evidently one of the ports listed is a dedicated administrator port. Who knows, it might have succeeded if I logged out of SSMS.
I also ran this script - don't know if it was required or not.
B4X:
USE master
Go
GRANT CONNECT ON ENDPOINT::[TSQL Default TCP] to [skdata]
go
GRANT CONNECT SQL TO "skdata"
Since my server is set to listen on any IP I chose the one above at random and it worked with the selected PORT.
How did I pick the port?
Again, look at the log and search for 'listening on'. This will show you what ports your server is actually listening on. Try those ports.
You MUST SELECT 'SQL Server and Windows Authentication Mode'. SSMS>Right-Click the DB>Properties>security page.
You can look at how it is all setup HERE: (Start>All Programs>Microsoft SQL Server XXXX>Configuration Tools>SQL Server Configuration Manager



My system is set up with listen all:

If your is not go to the IP Addresses Tab and see what is listening. Evidently the IP Addresses Tab is irrelevant if 'Listen All' is yes.
Any changes here require a server restart. Again the best place to see your addresses and Ports is look at the server log. It will tell you what it is listening on.

I would really liked to have gone with the server name but couldn't get it to work.

Addendum:
All of the above got things working LOCALLY. The minute I tried to access from the tablet it failed. This was a firewall issue NOT on the WINDOWS computer but with the WIRELESS ROUTER. I had to go in to the router and port forward my port, so the IP on the TABLET actually wound up being the IP of the COMPUTER that the server was installed on. There you can use (I think) whatever port you want as long as it is forwarded to the port you have selected for your RDC.

Addendum2:
Where I say above that the IP address doesn't matter IS TRUE ONLY IF THE RDC IS SET UP ON THE SAME COMPUTER AS THE SQL SERVER! If you are setting up the RDC on another computer then the IP address must be the IP of the SQL SERVER computer. So:
B4X:
JdbcUrl=jdbc:jtds:sqlserver://127.5.5.1:49959/AndroidTest
Becomes:
B4X:
JdbcUrl=jdbc:jtds:sqlserver:SERVER.IP.ADDRESS:49959/AndroidTest

NOTE that all of this I am testing on Windows 7/8 computers. The rules may be different for an actual windows server.

Hope this helps someone.

Kim
 
Last edited:

buras3

Active Member
Licensed User
Longtime User
hello

can anyone help me ?


C:\Users\Michael\Downloads\RemoteDatabaseConnector>"C:\Program Files (x86)\Java\
jre7\bin\java" -Xmx256m -cp .;libs\*;jdbc_driver\* anywheresoftware.b4a.remoteda
tabase.RemoteServer
B4A Remote Database Connecter (version 0.9)
loading: C:\Users\Michael\Downloads\RemoteDatabaseConnector\config.properties
2014-07-27 12:48:40.785:INFO::jetty-7.4.2.v20110526
2014-07-27 12:48:40.815:INFO::started o.e.j.s.ServletContextHandler{/,null}
Θσ∞ 27, 2014 12:48:40 PM com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
Θσ∞ 27, 2014 12:48:40 PM com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.2.1 [built 20-March-2013 11:16:28 +0000; debug? true
; trace: 10]
2014-07-27 12:48:41.055:INFO::Started SelectChannelConnector@0.0.0.0:1433 STARTI
NG
Θσ∞ 27, 2014 12:48:44 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource g
etPoolManager
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acqu
ireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCo
mmitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> fa
lse, checkoutTimeout -> 20000, connectionCustomizerClassName -> null, connection
TesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceN
ame -> 2rvxtt93x2vju31hakpiz|be8216, debugUnreturnedConnectionStackTraces -> fal
se, description -> null, driverClass -> net.sourceforge.jtds.jdbc.Driver, factor
yClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToke
n -> 2rvxtt93x2vju31hakpiz|be8216, idleConnectionTestPeriod -> 600, initialPoolS
ize -> 3, jdbcUrl -> jdbc:jtds:sqlserver://127.0.0.1:1433/SQLMICHAEL est, max
AdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 1800, maxIdle
TimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 150, maxStatemen
tsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuer
y -> null, properties -> {user=******, password=******}, propertyCycle -> 0, sta
tementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testC
onnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides ->
{}, usesTraditionalReflectiveProxies -> false ]
Θσ∞ 27, 2014 12:49:17 PM com.mchange.v2.resourcepool.BasicResourcePool$Scattered
AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@2a46
d1 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to a
cquire a needed new resource, we failed to succeed more than the maximum number
of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: I/O Error: Unknown packet type 0x48
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2481)
at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:632)
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:3
71)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManag
erDataSource.java:146)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti
on(WrapperConnectionPoolDataSource.java:195)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti
on(WrapperConnectionPoolDataSource.java:184)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionRe
sourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResource
Pool.java:1086)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPe
ndingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourc
ePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.ru
n(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(Thre
adPoolAsynchronousRunner.java:648)
Caused by: java.io.IOException: Unknown packet type 0x48
at net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.java:8
61)
at net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket.java
:731)
at net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStream.jav
a:477)
at net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.java:114
)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2368)
... 12 more

Θσ∞ 27, 2014 12:49:17 PM com.mchange.v2.resourcepool.BasicResourcePool forceKill
Acquires
WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicR
esourcePool@111057b is interrupting all Threads waiting on a resource to check o
ut. Will try again in response to new client requests.
java.sql.SQLException: An attempt by a client to checkout a Connection has timed
out.
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConne
ction(C3P0PooledConnectionPool.java:687)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(A
bstractPoolBackedDataSource.java:140)
at anywheresoftware.b4a.remotedatabase.Servlet.doGet(Servlet.java:64)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538
)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java
:478)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandl
er.java:937)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:
406)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandle
r.java:871)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.j
ava:117)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper
.java:110)
at org.eclipse.jetty.server.Server.handle(Server.java:346)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.
java:589)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete
(HttpConnection.java:1048)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:601)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)

at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:41
1)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEn
dPoint.java:535)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEnd
Point.java:40)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool
.java:529)
at java.lang.Thread.run(Unknown Source)
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out whil
e waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePo
ol@111057b -- timeout at awaitAvailable()
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicRes
ourcePool.java:1416)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(
BasicResourcePool.java:606)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicR
esourcePool.java:526)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConn
ectionInUse(C3P0PooledConnectionPool.java:755)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConne
ction(C3P0PooledConnectionPool.java:682)
... 21 more
Θσ∞ 27, 2014 12:49:17 PM com.mchange.v2.resourcepool.BasicResourcePool$Scattered
AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@1dba
d5b -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to
acquire a needed new resource, we failed to succeed more than the maximum number
of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: I/O Error: Unknown packet type 0x48
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2481)
at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:632)
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:3
71)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManag
erDataSource.java:146)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti
on(WrapperConnectionPoolDataSource.java:195)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti
on(WrapperConnectionPoolDataSource.java:184)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionRe
sourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResource
Pool.java:1086)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPe
ndingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourc
ePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.ru
n(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(Thre
adPoolAsynchronousRunner.java:648)
Caused by: java.io.IOException: Unknown packet type 0x48
at net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.java:8
61)
at net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket.java
:731)
at net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStream.jav
a:477)
at net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.java:114
)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2368)
... 12 more

Θσ∞ 27, 2014 12:49:17 PM com.mchange.v2.resourcepool.BasicResourcePool$Scattered
AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@1742
9c2 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to
acquire a needed new resource, we failed to succeed more than the maximum number
of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: I/O Error: Unknown packet type 0x48
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2481)
at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:632)
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:3
71)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManag
erDataSource.java:146)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti
on(WrapperConnectionPoolDataSource.java:195)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti
on(WrapperConnectionPoolDataSource.java:184)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionRe
sourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResource
Pool.java:1086)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPe
ndingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourc
ePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.ru
n(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(Thre
adPoolAsynchronousRunner.java:648)
Caused by: java.io.IOException: Unknown packet type 0x48
at net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.java:8
61)
at net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket.java
:731)
at net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStream.jav
a:477)
at net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.java:114
)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2368)
... 12 more

Θσ∞ 27, 2014 12:49:17 PM com.mchange.v2.resourcepool.BasicResourcePool forceKill
Acquires
WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicR
esourcePool@111057b is interrupting all Threads waiting on a resource to check o
ut. Will try again in response to new client requests.
Θσ∞ 27, 2014 12:49:17 PM com.mchange.v2.resourcepool.BasicResourcePool forceKill
Acquires
WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicR
esourcePool@111057b is interrupting all Threads waiting on a resource to check o
ut. Will try again in response to new client requests.
 
Last edited:

buras3

Active Member
Licensed User
Longtime User
Sql server 2008 R2

Is this the file i need to put in folder jdbc_driver : jtds-1.3.1.jar?
 

buras3

Active Member
Licensed User
Longtime User
I have tried with with\without port ,instance name , computer name \IP
in vb6 and vb.net it's working
Dim ConString As String = "Data Source=127.0.0.1\SQLMICHAEL;Initial Catalog=test;User ID=sa;Password=333"

**Edit RunRLc**
"C:\Program Files (x86)\Java\jre7\bin\java" -Xmx256m -cp .;libs\*;jdbc_driver\* anywheresoftware.b4a.remotedatabase.RemoteServer
pause

**config file**
#Lines starting with '#' are comments.
#Backslash character at the end of line means that the command continues in the next line.
#DriverClass=net.sourceforge.jtds.jdbc.Driver
#JdbcUrl=jdbc:jtds:sqlserver://127.0.0.1\test

#SQL Server
DriverClass=net.sourceforge.jtds.jdbc.Driver
JdbcUrl=jdbc:jtds:sqlserver://127.0.0.1\test

User=sa
Password=333
ServerPort=1433
#If Debug is true then this file will be reloaded on every query.
#This is useful if you need to modify the queries.
Debug=true

#commands
sql.create_table=CREATE TABLE animals (\
id INT NOT NULL AUTO_INCREMENT,\
name CHAR(30) NOT NULL,\
image BLOB,\
PRIMARY KEY (id))
sql.insert_animal=INSERT INTO animals VALUES (null, ?,?)
sql.select_animal=SELECT name, image FROM animals WHERE name = ?
 

buras3

Active Member
Licensed User
Longtime User
same problem

#SQL Server
DriverClass=net.sourceforge.jtds.jdbc.Driver
JdbcUrl=jdbc:jtds:sqlserver://127.0.0.1/test

User=sa
Password=333
ServerPort=17178
 

buras3

Active Member
Licensed User
Longtime User
I got it!! by changing all ports to 1433 in sql configuration manager
tank you
 
Last edited:

MrKim

Well-Known Member
Licensed User
Longtime User
Is it possible to set a null value? I have field that sometimes needs to be set back to Null. Putting the Keyword Null in my parameters puts the word null in the data.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…