I have a SQL Database in Microsoft Azure.I want to access this SQL database from a java application in eclipse. The Azure portal has a provision for adding client IP address to firewall settings of Azure SQL Database.Only these IP addresses are allowed to access the database.And now I am stuck in coding to allow access to a given ip address programmatically . Can anyone help?
This is the Exception i am getting :
com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open server 'pluginserver' requested by the login. Client with IP address '105.241.8.90' is not allowed to access the server. ClientConnectionId:7c605cae-5bb6-452e-a606-243b1fab304f
While researching i got code to do the same in c#.But i want the code in java.
public void AddFirewallRule(FirewallRule rule)
{
using (SqlConnection conn = new SqlConnection(this.ConnectionString))
using (SqlCommand cmd = conn.CreateCommand())
{
conn.Open();
cmd.CommandText = "sp_set_firewall_rule";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = rule.Name;
cmd.Parameters.Add("@start_ip_address", SqlDbType.VarChar).Value = rule.startIPAddress.ToString();
cmd.Parameters.Add("@end_ip_address", SqlDbType.VarChar).Value = rule.endIPAdress.ToString();
cmd.ExecuteNonQuery();
}
}