Connect Android Studio with SQL Server fails - sql-server

I am developing an android application and I am trying to connect Android Studio with an SQL Server Database. I try the following:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
connectionSql = "jdbc:sqlserver://IP_SERVER/EXPRESS;database=myDatabase";
connection = DriverManager.getConnection(connectionSql,"username","password");
However, I am getting the following log error:
The TCP/IP connection to the host IP_SERVER/EXPRESS, port 1433 has failed. Error: "Unable to resolve host "IP_SERVER/EXPRESS": No address associated with hostname. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
However, I have added firewall rules to the server both inbound, outbound for this port. Also another local web apps (servlets) can access this database so the error I am getting isn't quite right.
I suspect that the problem is this IP_SERVER/EXPRESS. When I am logging from SQL Management Studio to the database I am using as server name the IP_SERVER\EXPRESS. So I tried the following
connectionSql = "jdbc:sqlserver://IP_SERVER\\EXPRESS;database=myDatabase";
but I got an error
FATAL EXCEPTION: main
Process: com.example.jdbc, PID: 11553
java.lang.AssertionError: numMsgsRcvd:1 should be less than numMsgsSent:1
at com.microsoft.sqlserver.jdbc.TDSReader.readPacket(IOBuffer.java:6430)
at com.microsoft.sqlserver.jdbc.TDSReader.nextPacket(IOBuffer.java:6396)
at com.microsoft.sqlserver.jdbc.TDSReader.ensurePayload(IOBuffer.java:6374)
at com.microsoft.sqlserver.jdbc.TDSReader.readBytes(IOBuffer.java:6675)
at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.readInternal(IOBuffer.java:846)
at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.read(IOBuffer.java:836)
at com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.readInternal(IOBuffer.java:1006)
at com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.read(IOBuffer.java:996)
at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.readFromSocket(ConscryptEngineSocket.java:945)
at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.processDataFromSocket(ConscryptEngineSocket.java:909)
at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.-$$Nest$mprocessDataFromSocket(Unknown Source:0)
at com.android.org.conscrypt.ConscryptEngineSocket.doHandshake(ConscryptEngineSocket.java:241)
at com.android.org.conscrypt.ConscryptEngineSocket.startHandshake(ConscryptEngineSocket.java:220)
at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1802)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2558)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2216)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:2067)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1204)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:825)
at java.sql.DriverManager.getConnection(DriverManager.java:580)
at java.sql.DriverManager.getConnection(DriverManager.java:218)
at com.example.jdbc.SQLConnection.connectionClass(SQLConnection.java:26) <--- this line point to connection = DriverManager.getConnection(connectionSql,"username","password");
at com.example.jdbc.MainActivity$1.onClick(MainActivity.java:43)
at android.view.View.performClick(View.java:7506)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1194)
at android.view.View.performClickInternal(View.java:7483)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:29335)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Any help is appreciated, I am new to android programming.
Update
I also tried
connectionSql = "jdbc:sqlserver://IP_SERVER;instanceName=EXPRESS;database=myDatabase;integratedSecurity=true;";
but I am getting the same error...
java.lang.AssertionError: numMsgsRcvd:1 should be less than numMsgsSent:1

Related

Getting com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host for AWS SQL Server 2017

Kubernets deployment of application on AWS is giving following error while connecting to a SQL Server RDS instance
org.apache.naming.NamingContext.lookup Unexpected exception resolving reference
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host , port 1433 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.
Tried enabling all the traffic in the security group inbound rule also the ec2 instance VPC and RDS VPC has peer connection link, not sure what is the issue causing this error
I found the root cause for this issue, if someone like me stuble upon this question/issue in future then the issue was due to the Route not having the EC2 instance VPC's entries.

AWS RDS Instance is not connecting to Jmeter

I am trying to connect my RDS instance to a Jmeter load test however no matter what I try, I keep getting this error message in the Results Tree:
Cannot create PoolableConnectionFactory (The connection to the host database-1.cqdkrfikhe1t.us-east-1.rds.amazonaws.com, named instance database-1 failed. Error: "java.net.SocketTimeoutException: Receive timed out". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.)
I feel it may be a problem with my Database URL in JDBC Connection Configuration.
The picture below shows the summary report.
I have mainly tried rewriting the Database URL multiple different ways but none of them seem to work. I have also tried removing and reinstalling the JDBC Drivers but that doesn't seem to work either. I have absolutely no idea what the problem could be. Could someone please help me out with this problem?
Edit: When I change the Database URL I sometimes get this error
message as well:
Cannot create PoolableConnectionFactory (The driver could not establish a secure connection to SQL Server by using Secure Sockets
Layer (SSL) encryption. Error: "PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target".
ClientConnectionId:9b700d73-f3f0-4cf6-b3a4-607fa9827219)
I think you need to use port 1433
Check out Connecting to a DB instance running the Microsoft SQL Server database engine article
So cross check the port number, VPC options, public accessibility, etc. with the values from the JDBC Connection Configuration
More information: The Real Secret to Building a Database Test Plan With JMeter

HTTP Error 500.30 - ANCM In-Process Start Failure - An error occured during migration

I have read this thread, however unfortunately couldn't find the solution to my problem. I have an ASP.Net Core project (that's called Rent) and it works without any problem on my local machine. However, once I publish the project to the IIS (still in development mode) I get the below error
fail: Rent.Program[0]An error occured during migration
Microsoft.Data.SqlClient.SqlException (0x80131904): 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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
---> System.ComponentModel.Win32Exception (0x89C50118): Unknown error (0x89c50118)
The connection string is called DefaultConnection and is the environment variable. Can anyone help me please? Can provide any additional information if required.
The first thing you should check is that your SQL Server instance is up and running and that your database is still available. This error means quite literally that it can't establish a connection to SQL Server from the Secret Server application.
And you can also check follow things in your environment:
Is something blocking the connection between your Secret Server server and SQL Server?
The standard SQL port is 1433. Check with your server administrator - is the Windows Firewall in use, blocking this port on your SQL server? Check with your network administrator - is there a firewall at some point in between that has closed off this port? Keep in mind that if you use a custom port for SQL, it need to be specified the Secret Server database connection using a SQLSERVER,port type of format.
On the server hosting your SQL Server database, is the SQL Server
service running?
Open services.msc or SQL Configuration Manager to view the status of your SQL Server service.

Can't Connect to SQL Server Remotely (TCP Error)

I am having an issue connecting to my SQL Server Database remotely from another computer.
I am trying to connect to the database using a VB.Net application that is suppose to be able to interact with it. I'd say my connection string may be the issue, but I have no problem connecting on the machine the database is on using the connection string.
This is what the connection string looks like though:
"Data Source=[IP_ADDRESS],[PORT];Network Library=DBMSSOCN;Initial Catalog=SQL_Database;Persist Security Info=True;User ID=[USER];Password=[PASS]"
The error I am getting right now is:
Database 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. (provider: TCP Provider. error: 0 - The wait operation timed out.).
This is what I have done so far to try to get this to work:
I have made sure that the files being run are on not a network/shared drive.
I've added an exception for TCP Port 1433 and UDP Port 1434 as Incoming Rules to the Firewall.
I've tried disabling the firewall.
I have gone into SQL Server Configuration Manager to ensured that the TCP settings are setup properly.
One thing I am not sure about, is that in the Configuration Manager, I have both the SQL Server and SQL Server Browser running, but the SQL Server Agent is unable to start. Would this cause me my problem?
If not, what else could be my issue? I need to be able to access this database remotely, but the connection string seems to only work locally.
So the issue was literally my company's installed network Firewall. Apparently when I asked if the firewall had been put down for me to test this, "Yes" really meant "No". Once I got the firewall temporarily disabled I was able to connect to everything perfectly fine.

Having trouble with SQL Server connection on WebSphere 8.5

I'm having all kinds of trouble getting IBM WebSphere 8.5 to connect to my SQL Server 2012 data source. I have the URL of jdbc:sqlserver://localhost;userName=user;password=password. See the following error (I know it's kind of long):
The test connection operation failed for data source reachingrecovery on server server1
at node MWEISS7X16Node01 with the following exception: java.sql.SQLException: The TCP/IP
connection to the host localhost, port 1433 has failed. Error: "Connection refused:
connect. Verify the connection properties. Make sure that an instance of SQL Server is
running on the host and accepting TCP/IP connections at the port. Make sure that TCP
connections to the port are not blocked by a firewall."
Now, the SQL server and WebSphere are running on the same machine, so I don't think it's a firewall issue. I've checked the SQL server properties under "Connections", and it indicates that everything is fine ("Allow remote connections to the server" is checked.)
I'm at a loss to understand why this is happening. Any suggestions? Thx Mimi
I found out what the problem was. I was using SQL Server Management Studio to check on whether it could make TCP/IP connections or not. What I should have been using was SQL Server Configuration Manager. It had a thing on the left called "SQL Server Network Configuration". I clicked on that, and it brought up "Protocols for server instance name". It had a thing on the right (TCP/IP), which indicated it was disabled. I enabled that, restarted the SQL server, and it worked.

Resources