I know this question has been asked many times before but I have been through all the threads and I am still having issues.
I am trying to connect a c# application to insert data to an azure SQL database.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "claimsportaldbserver.database.windows.net";
builder.UserID = "[email protected]@claimsportaldbserver";
builder.Password = "password";
builder.InitialCatalog = "Claims Portal_db";
try
{
using (Microsoft.Data.SqlClient.SqlConnection connection = new Microsoft.Data.SqlClient.SqlConnection(builder.ConnectionString))
{
String sql = "SELECT * FROM [dbo].[Claims]";
using (Microsoft.Data.SqlClient.SqlCommand command = new Microsoft.Data.SqlClient.SqlCommand(sql, connection))
{
connection.Open();
using (Microsoft.Data.SqlClient.SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine("{0} {1}", reader.GetString(0), reader.GetString(1));
}
}
}
}
}
catch (Exception ex)
{
return ex.InnerException.ToString();
}
Below is a list of things I have tried which were from various forms and documentation
- I copied the connection string details from azure so there are no spelling mistakes.
- Added my IP address to the azure firewall rules.
- Added port 1433 to my own firewall rules.
- Use Microsoft.Data.SqlClient and not System.Data.SqlClient.
- Added ServicePointManager.SecurityProtocol to the code.
- Added WebRequest.DefaultWebProxy.Credentials to the code.
However, I am still getting the message “A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 – The wait operation timed out.)”
Any help would be appreciated.
Thank you