Я пытаюсь подключить SQL Azure из моего приложения для Android.Код работает нормально для приложения Java, где мне удалось получить данные из SQL Azure, но он выдает ошибку для моего Android.Ниже мой код и сообщение об ошибке.
Код:
String connectionString =
"jdbc:sqlserver://serversql.database.windows.net:1433" + ";" +
"database=dbname " + ";" +
"user=user@serversql" + ";" +
"password=password";
Connection connection = null; // For making the connection
Statement statement = null; // For the SQL statement
ResultSet resultSet = null; // For the result set, if applicable
try
{
// Ensure the SQL Server driver class is available.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// Establish the connection.
connection = DriverManager.getConnection(connectionString);
String filename = "SVPoster.jpg";
String sql = "Select * from VoucherTable";
statement = connection.createStatement();
resultSet = statement.executeQuery(sql);
int count;
if(resultSet.next())
{
Blob test = resultSet.getBlob("Voucher");
InputStream x=test.getBinaryStream();
int size=x.available();
OutputStream output = new FileOutputStream("/sdcard/"
+ filename);
byte data[] = new byte[1024];
long total = 0;
while ((count = x.read(data)) != -1) {
total += count;
output.write(data, 0, count);
}
output.flush();
output.close();
x.close();
}
}
catch (Exception ex)
{
Toast.makeText(getApplicationContext(), ex.toString(),
Toast.LENGTH_LONG).show();
}
Сообщение об ошибке
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host server.database.windows.net, port 1433 has failed. Error: "null. 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.".