1
votes

I have api appservice in my azure and also I have VM with SQL Server installed. Now I would like to connect to the database on the vm. I keep getting the following connection error when provide the connection string to api as :

Server=db-svr;Initial Catalog=DBName;Persist Security Info=False;User ID=userid;Password=password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

System.AggregateException: One or more errors occurred. (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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server))

System.Data.SqlClient.SqlException: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

System.ComponentModel.Win32Exception: Access is denied
--- End of inner exception stack trace ---

at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)

My VM -> Overview : There is no DNS name configured and no public ipaddress. That is the reason I used computer name.

Also the VM->Networking has got the following inbound rule.

enter image description here

Can anyone help how to connect my app service to the SQL Server database available in this VM?

Thanks

1

1 Answers

1
votes

This is because they have to talk to each other over the internet, so you have to provide a proper dns name for the sql server or use a static Public IP for it.

You can, technically, use vpn in webapp, but that complicates things a bit.