I'm trying configure a app in Spring Boot to connect with Azure DataBase using com.microsoft.sqlserver.jdbc.SQLServerDriver driver.
This is my configuration:
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://hdonrns815.database.windows.net:1433;databaseName=code_dev
spring.datasource.username=user
spring.datasource.password=password
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServerDialect
spring.jpa.show-sql=true
this is my SQL Server pom.xml configuration:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
And this is the error:
com.microsoft.sqlserver.jdbc.SQLServerException: SQL Server did not return a response. The connection has been closed. ClientConnectionId:d7304f30-4c29-4258-ac9f-4409dee20fdd
I can connect to the DB from Sql Server management.
I don't know what happend.
Thanks.
Allow Azure Services to access Azure SQL.
Reference: https://learn.microsoft.com/en-us/azure/sql-database/sql-database-firewall-configure#connecting-from-azure
Related
I'm trying to develop an Umbraco 8.1.1 site on Azure and am following these steps:
I create an Azure SQL server database (I don't use any local DB at all).
I create an empty ASP.NET 4.7 Web App locally and add Umbraco 8.1.1 via NuGet
I invoke locally and configure my Umbraco application to use the Azure SQL Server DB. It works without issue. I can see the database from SQL Server Management Studio no problem.
I then publish the site through Visual Studio 2019 to an Azure Web App, and when I visit it, I get the following error:
Server Error in '/' Application.
Boot failed: Umbraco cannot run. See Umbraco's log file for more
details.
-> Umbraco.Core.Exceptions.BootFailedException: A connection string is configured but Umbraco could not connect to the database. at
Umbraco.Core.RuntimeState.DetermineRuntimeLevel(IUmbracoDatabaseFactory
databaseFactory, ILogger logger) in
d:\a\1\s\src\Umbraco.Core\RuntimeState.cs:line 194 at
Umbraco.Core.Runtime.CoreRuntime.DetermineRuntimeLevel(IUmbracoDatabaseFactory
databaseFactory, IProfilingLogger profilingLogger) in
d:\a\1\s\src\Umbraco.Core\Runtime\CoreRuntime.cs:line 259 at
Umbraco.Core.Runtime.CoreRuntime.Boot(IRegister register,
DisposableTimer timer) in
d:\a\1\s\src\Umbraco.Core\Runtime\CoreRuntime.cs:line 146
I'm stumped. How do you configure Umbraco to use an Azure SQL DB?
Check that you've got the connection string registered in the Web App correctly - I suggest looking at the Configuration section for the Web App and setting the configuration string there. Alternatively, download your web.config file via ftp and compare the connection string in the published version vs. your local version.
You should also check the server or database firewall settings and make sure that Azure services have access:
https://learn.microsoft.com/en-us/azure/sql-database/sql-database-firewall-configure#connecting-from-azure
I'm trying to build a webservice that talks to a SQL database hosted on a server in our internal network. The service is hosted by Azure as a Web App. Is there a good way of doing this? Do I have to use Azure Sql databases, and if I do, is there a way to have the Azure database act as a proxy for our internal database?
There are already rules permitting connections to the ports on our database server, so I don't think that's the problem. I see a lot of questions regarding connecting to Azure hosted sql databases, but nothing about connecting Azure web apps to other kinds of databases.
The error occurs when I try to call a stored procedure (via generated entity framework code) and is as follows:
Error occurred: System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> 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.
Our database is configured to allow remote connections, so what I'm guessing the Web App is having difficulty connecting to our vpn.
Please let me know if you need any additional information.
Thanks,
Josh
You can leverage Azure Hybrid Connections which is a feature of App service. Within App Service, Hybrid Connections can be used to access application resources in other networks. It provides access from your app to an application endpoint and uses Azure Relay service to connect to on-premise.
Check out the below link for more details :
https://learn.microsoft.com/en-us/azure/app-service/app-service-hybrid-connections
First option is to look on azure app service hybrid connection but for you to do that you should have Windows server 2012 or above.
Azure App Service Hybrid
Azure App Service hybrid connection is good if you are pulling small amount of data.
If you are pulling large amount of data or your SQL server version is below server 2012 you have two options:
Azure Site to Site VPN
Azure SQL Data Sync
Azure SQL DB Sync is a feature that available on Azure SQL database. You can create a Azure SQL database on azure and sync your on-premise SQL database or SQL database table to Azure SQL database and you can connect your application to Azure SQL database instead of connecting to on-premise database server. This will increase your performance of your application.
We ended up adding the application to an Azure Virtual network that allowed connections to our on-prem servers. The remaining difficulties were due the wrong port numbers being open.
What was very helpful in debugging this was the Kudu console in Azure, under Advanced tools -> console. There you can run commands from the machine hosting your application like ping, or the below:
sqlcmd -S tcp:servername,1433 -U Username -d databasename -P password -q "SELECT * FROM tablename"
not able to connect google cloud sql from google app engine
getting
logMessage: "[
j~gcp-ws-203608/20180510t123822.409615356828549281].<stdout>: 2018-05-10 07:20:08.036 ERROR 1 --- [Request5396402F] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_112-google-v7]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_112-google-v7]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_112-google-v7]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_112-google-v7]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[jdbc-mysql-connector.jar:na]
at com.mysql.jdbc.Util.getInstance(Util.java:386) ~[jdbc-mysql-connector.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1014) ~[jdbc-mysql-connector.jar:na]
dependency used:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory-connector-j-6</artifactId>
<version>1.0.5</version>
</dependency>
It seems that something might be wrong with the way you are setting up the connection to the database.
Please make sure that:
The proper service account for accessing Cloud SQL from App Engine is setup (if the App Engine application and the Cloud SQL instance are in different Google Cloud Platform projects)
You have an already created database in Cloud SQL
You have added all the correct parameter values (Cloud SQL instance connection name, database, user, and password) to the pom.xml file.
You are creating a connection URL and establishing a connection to the database in the same way it is done in this example
I have my api running on Azure and it is working perfect if it is connected to Azure SQL database.
I want this api to use my local database i.e on-premises database. I made my database to accept connection from remote and also enabled TCP/IP in wf.msc and also created an inbound rule for 1433. Is there anything i had to do to make this work? I tried to use the following connection string in azure :
ASP.Net core 2.0 web api written in C# hosted on azure and trying to access the sqlserver database on the Virtual Machine.
I tried as mentioned in the following to create hybrid connection but the status keeps saying 'Not Connected'
https://learn.microsoft.com/en-us/azure/app-service/app-service-hybrid-connections
Server=tcp:<mycomputername>,1433;Initial Catalog=MyDb;Persist Security Info=False;User ID=userid;Password=pwd;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
If your On-Prem SQL VM is behind firewall, you need to allow inbound from Azure. Usually you poke a hole in your On-Prem firewall and allow inbound from your Azure (source) to your On-Prem SQL server (Destination) on a particular port.
I have what I thought would have been a pretty normal scenario...
I have a
-WCF Client
-WCF service hosted in AppFarbic within IIS7.5
-SQL Server 2008 r2
IIS is running using the App Pool Identity
I am connecting from the client using the following config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint
name="NetTcpBinding_IXXXService"
address="net.tcp://app02.xx.com/XXXService/XXXService.svc"
binding="netTcpBinding"
contract="XXXClient.IXXXService">
<identity>
<servicePrincipalName value="host/app02.xx.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
IIS is running using the application pool identity.
I can get the service to connect to the database if I create a \$ login.
When using the application pool identity is this the only way of connecting to the database using Windows authentication?
I presume this is allowing the Network Service account on this machine to access the database. I also presume that this also means any service running as network can access the database?
Is there any of way of tying the application pool identity to the database login?
EDIT: When I change the user of the App Pool to be another user with access to the database I get an SSPI failed error
Please forgive me for taking a stab at this when I am not familiar with WCF or AppFarbic. Though I do know a little about IIS and authentication to SQL server on different server.
Can you connect to the database if you use username-based security with a password?
What authentication method are you using on the web site?
If you are trying to use integrated Windows authentication and your web authentication method is also integrated, then you have to use Kerberos security in IIS to allow delegation for the "second hop" over the network to the SQL server. Regular NT security is not enough because it can only do impersonation, which doesn't allow this. Getting delegation to work can be a pain in the butt, but you have to examine the SPN you're using and make sure it's properly registered on the SQL server, plus mess around with IIS to make sure that Kerberos is enabled and actually working instead of it silently slipping back to NTLM. The web server also has to be "trusted for delegation" in the domain group policy (assuming your web server is joined to a domain).