I'm developing an android application. I need connect to sql server. I wrote a code for test connection but i get this error :
java.sql.SQLException: Network error IOException: Permission denied
I checked connection string.
I closed firewall for 1433.
I tried configured Sql Server tcp and remote access settings
but i still get the same error. What is my mistake?
My environment:
Sql Server 2008 R2
Eclipse
jtds
My Code is:
try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
**Connection conn=DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.1.33:1433/Android_Deneme;instance=CASPER\\MORTY;user=ugur;password=1234");**
String sql="insert into tablo1(ad,yas) values(?,?)";
PreparedStatement prepared = conn.prepareStatement(sql);
prepared.setString(1, "ali");
prepared.setInt(2, 30);
prepared.executeUpdate();
}
catch(Exception e)
{
e.printStackTrace();
}
You have to add the following permission to your application manifest file.
<manifest>
.....
<uses-permission android:name="android.permission.INTERNET" />
.....
</manifest>
Related
httpURI = 'http://17.25.16.68:4000/graphql' //example
const httpLink = createHttpLink({ uri: httpURI });
const client = new ApolloClient({ link:httpLink, cache: new InMemoryCache() });
The connection works on debug mode, but when I run it on release, no connection is made.
Do I need to enable outgoing connections somewhere in the Android release config?
This is something that worked for me. apparently android pie doesn't allow network requests to URLs without https.
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
This file allowed android for reaching http requests.
In android/app/src/main/AndroidManifest.xml add the line below
<application
.
.
.
android:usesCleartextTraffic="true"
.
.
.
>
</application>
I am using following code and getting permission denied error.
if ((mSockFd = socket(PF_KEY, SOCK_RAW, PF_KEY_V2)) < 0) {
LOGE("IPSec Init : PF_KEY socket creation failed");
LOGE("mSockFd : %d, Error no : %d",mSockFd,errno);
LOGE("Error String : %s",strerror(errno));
}
I have added following permission in AndroidMenifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Please help me solve this problem.
Where
PF_KEY is a new socket protocol family used by trusted privileged
key management applications to communicate with an operating
system's key management internals
To open SOCK_RAW type socket you need to have root privileges. If you are trying to run this on Mobile then phone must be rooted. Or try to implement in Linux Machine you will get root privilege easily.
I wrote a program to access Microsoft sql database. It works fine in desktop. But when I run same program in android device I’m getting error:
04-09 06:17:41.784: W/Qt(1240): kernel\qsqlquery.cpp:368 (bool
QSqlQuery::exec(const QString&)): QSqlQuery::exec: database not open
Here is my code:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={SQL Server};Server=192.168.1.3;Database=sms_exp;");
db.setUserName("sa");
db.setPassword("xxxxxyy");
if(!db.open())
{
qDebug ("Error");
}
else
{
qDebug ("OK");
}
QSqlQuery query (db);
query.exec("SELECT item_code, item_des FROM prod_mast WHERE item_code = 0100000210");
while (query.next())
{
QString name1 = query.value(0).toString();
QString name2 = query.value(1).toString();
qDebug (qPrintable(name1));
qDebug (qPrintable(name2));
}
db.close();
There is no Android build of the ODBC driver. If you check QSqlDatabase::drivers() you will see that only SQLite driver is supported for android in Qt.
The only way of making an ODBC connection on android is to use a JDBC-ODBC bridge that supports network connections between the client and the server. JDBC on Android to ODBC on a windows machine and then to the MS Access ODBC driver.
I have an apache server installed in my PC where I host one PHP file.
Then I tried to connect to that file using eclipse, but it always gives me below error
connection to http://10.0.2.2:8080 refused.
I tried changing address to the followings, but got similar error all the time.
http://10.0.2.2
http://127.0.0.1
http://localhost
Can anyone please help me.
EDITED: Just for information, I can access to remoter server (e.g. www.mydomain.com) without any problem.
CLASS FILE:
HttpClient httpclient = new DefaultHttpClient();
Log.d("test","t0");
HttpPost httppost = new HttpPost("http://10.0.2.2:8080/mylibman/data.php");
Log.d("test","t1");
HttpResponse response = httpclient.execute(httppost); // error here
Log.d("test","t2");
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.migrationdesk.mylibman"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
Error LogCat:
11-16 02:02:20.803: E/log_tag(1427): Error in http connection org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2:8080 refused
11-16 02:02:20.803: E/log_tag(1427): Error converting result java.lang.NullPointerException: lock == null
11-16 02:02:20.803: E/log_tag(1427): Error parsing data org.json.JSONException: End of input at character 0 of
alright go to Apache httpd.conf (located in Apache folder): and search for
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
and check if the second line is Deny, if it is then change it to:
Allow from all
then restart the Appache server, and tell me the feadback.
Edit
try it out in your real device:
go to CMD and type ipconfig under IPv4 take the IP address and change the IP it will look similar to this:
http://192.168.0.106:8080/mylibman/data.php // similar to this.
Turn Off the firewall and any anti-virus application in your PC
and please give me the feedback.
Mike helped me a lot on this issue. So here my steps to avoid this Connection refused.
1) Add if to test Android SDK. It seems that in new versions you have to explicity allow the connection to be open in a different thread:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
System.out.println("*** My thread is now configured to allow connection");
}
...
2) Add an exception for your port:
in your case allow inbound connection for port 8080
3) test your connection by browsing the desired url locally
use your browser and try to visit http://10.0.2.2:8080 locally
4) Add in your manifest file a permission for internet:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourapp"
android:versionCode="1"
android:versionName="1.1" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
I am using Wamp, and its apache is listening to servername localhost and port 8080 (allow from all in httpd.conf).
My local IP is something similar to 192.168.0.XXX/folder/my-page-here
You can use your real IP address to reach your virtual server. Take a look at my answer here. I hope it helps.
if your SDK version is less then 9 then add above code for SDK version them some changes in Apache update httpd.conf as line deny from all..replace that sentence Allow from all and restart services of WAMP server then use 10.0.2.2 address or 10.0.2.2:8080 port no and include permission line in android AndroidManifest file
<uses-permission
android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
</uses-permission>
I fix this problem by writing my IP address from cmd -> ipconfig in the url :
HttpPost httppost = new HttpPost( "http://192.168.x.x/mylibman/data.php" );
I am writing some code to connect my Android device to my Mac using bluetooth. Its seems to create a connection,(i am able to see my android in tbe connected list in Mac) But it throws an exception on the android device.
BluetoothDevice bd = mBluetoothAdapter.getRemoteDevice("00:26:08:BF:D0:22");
BluetoothSocket bs = null;
try {
bs = bd.createRfcommSocketToServiceRecord(DeviceSearchService.MY_UUID);
try {
bs.connect();
} catch (IOException ex) {
Log.i(TAG, "Exception in connecting to socket." + ex.getMessage(), ex);
}
}
The bs.connect is throwing an exception saying cannot connect to the device. The device in question is a Mac OSX laptop of mine. I am running this code from Galaxy S device.
THe UUID used is "00001101-0000-1000-8000-00805F9B34FB"
Am I missing something ?
have you declared the Bluetooth permissions in your application manifest file?
<manifest ... >
<uses-permission android:name="android.permission.BLUETOOTH" />
...
</manifest>