2

I'm trying to connect to a database from VS2017

 var str = str1.ConnectionString =
                "Data Source=141.*****.199;" +
                "Initial Catalog=****;" +
                "User id=***;" +
                "Password=****;";
                using (SqlConnection conn = new SqlConnection(str))
                {
                    try
                    {
                        conn.Open();
                        var text = "SELECT * FROM Users u WHERE u.Id=76769";
                           ...
                    }
                    catch (Exception e)
                    {
                        return req.CreateResponse(HttpStatusCode.OK, e.ToString());
                    }

and get error

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.

It's azure function. If I set this connection from LogicApp, then there are no errors. Why the connection does not work from the azure-function?

Janusz Nowak
  • 2,595
  • 1
  • 17
  • 36
  • Are you allowed to connect to an external DB form Azure Functions? – DavidG Mar 06 '18 at 13:29
  • In what environment is your Azure Function running? Public Azure? On-premises? in an ILB ASE? More information is required to help you with this question. – Chris Gillum Mar 06 '18 at 17:35

2 Answers2

0

can someone help. Functions refer to the database not with only ip , which are listed on the portal. They have several variants. And on the portal these addresses do not look, only through https: //resources.azure.com. And yes, you just need to specify in the firewall all valid values

0

I am connecting to an SQL DB from Azure Function, and I noticed a little difference in connection string that I am using.

Pls try and see if it works for you:

"Server=tcp:141.*****.199,1433;Initial Catalog=****;User ID=*****;Password=*****;"
  • 1433 - is the default MS SQL port number.
Dima G
  • 1,945
  • 18
  • 22