I'm unable to connect to a local SQL Server with jdbc. This server is authenticated by Windows Authentication. One thing to mention is that I successfully connected to a remote SQL Server with SQL Server Authentication.
My code:
String url = "jdbc:sqlserver://localhost\\SQLEXPRESS;integratedSecurity=true;databaseName=TP3S;";
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
Connection conn = DriverManager.getConnection(url);
I have enabled TCP/IP:
Any ideas? Thanks!
--UPDATE--
I have just started SQL Server Browser, now I'm getting the error:
WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication.
--UPDATE--
I solved the previous problem by adding -Djava.library.path="DLL path" in Run->Run configuration->Apache Tomcat->Arguments. But now I'm getting this error:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.
Under TCP/IP you can enable by IP address. Check if IPs are enabled.
Related
Background
I have a SQL Server database on my machine, using mixed mode auth and SQL users setup on the database and mapped. When connecting via .NET app, I am able to use both windows auth and sql auth without issues. However when connecting via AWS Schema Migration tool, I am not able to connect.
Checks done:-
SQL Server Browser Service running
Port mapping left to default (1433)
TCP/IP pipeline enabled
Done both sql and windows auth
Instance name given via ##servername command as per SCT doc
Windows user given dbo and serveradmin permissions at global level
and also granted Login and DB engine connect
Ignoring the port no
Ignoring the instance name
Unable to check firewall as both SQL and tool running on same machine
Using same SCT config, I can connect to SQL Server elsewhere so drivers seem to be working.
Log message below
When only localhost provided
com.amazon.sct.dbloader.DbLoaderHandledException: Connection wasn't established. Check connection properties.
java.util.concurrent.ExecutionException: com.amazon.sct.dbloader.DbLoaderHandledException: Connection wasn't established. Check connection properties.
When name provided for machine and instance
Connection to 'jdbc:sqlserver://localhost\DESKTOP-N01JO12:1433' wasn't established. ERROR: code: 0; message: 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.".
LOADER ERROR Error chain:
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."
Screenshots
For AWS SCT can access SQL server, the following conditions need to be satisfied:
DB has login account and user
User have to has admin role
SQL server authentication enabled
TCP/IP cho SQL server enabled
1. DB has login account and user
You can reference in this link:
https://www.guru99.com/sql-server-create-user.html
2. User have to has admin role
You can reference in this link: https://tableplus.com/blog/2018/10/how-to-create-user-with-admin-access-in-sql-server.html
3. SQL server authentication enabled
You can reference in this link:
SqlServer: Login failed for user
Note: Remember to restart SQL server
4. TCP/IP cho SQL server enabled
You can reference in this link: https://www.youtube.com/watch?v=p9mv2RP6Tck
==> Conclusion
I see you do all the think above
Here is my connection information for SQL server on my EC2 windows server
(I can't embed picture because I don't have enough reputation point)
Perhaps you should write connection information like me
Hope this help!
When I attempt to connect to my local, default SQL Server instance via SQL Management studio using Windows Authentication, I successfully connect when I use Server Name "localhost", but fail when I use Server Name "127.0.0.1". With login auditing enabled for both failed and successful logins, I see that the successful logins are recorded as:
Login succeeded for user 'AzureAD\RealUsername'. Connection made using Integrated Authentication. [CLIENT: < local machine >]
And the failed logins are recorded as:
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'. Reason: Could not find a login matching the name provided. [CLIENT: 127.0.0.1]
Possibly relevant:
I can connect using the ip address if I use SQL Server authentication (since I am forcing it to use an existing login).
There is no entry in my hosts file for "localhost", and when I ping localhost it does resolve to 127.0.0.1.
The SQL instance uses port 1433.
The issue, with very little variation, persists when connecting via SQL Management Studio, a .NET web app running in a local IIS instance, or via UDL file on my desktop.
Here is my question: Why would changing only the server value ('localhost' vs '127.0.0.1') change the identity used when connecting?
Hi I created a new login SQL server authentication in SQL server 2008, however I am unable to login with that user.
Getting an error like ,
TITLE: Connect to Server
Cannot connect to (local).
ADDITIONAL INFORMATION:
Login failed for user 'sa'. (Microsoft SQL Server, Error: 18456)
The error Login failed for user 'sa' means that connection to server was established, but server refused it under certain circumstances, such as:
Wrong password
Sql server uses only Windows Authentication (needs server restart)
In your Connection String you ask to connect to specified DB, which is not exists
sa login is Disabled or Denied to access sql engine
User Action
If you are trying to connect using SQL Server Authentication, verify
that SQL Server is configured in Mixed Authentication Mode.
If you are trying to connect using SQL Server Authentication, verify
that SQL Server login exists and that you have spelled it properly.
If you are trying to connect using Windows Authentication, verify
that you are properly logged into the correct domain.
If your error indicates state 1, contact your SQL Server
administrator.
From this article
Should this not help try troubleshooting this issue following these steps.
i must connect to a sql server with windows authentication
sql server is on machine 192.168.3.6
web server (client) is on my machine 192.168.3.10
I'm using JTDS driver
dbUrl=jdbc:jtds:sqlserver://192.168.3.6:1099/db_test;instance=test
Connection con = DriverManager.getConnection( dbUrl, "", "" );
I have username and password of administrator user of sql server !
I also put ntlmauth.dll into c:\windows and c:\windows\system32 and I have always error:
java.sql.SQLException: Login failed for user '(null)'. Reason: Not
associated with a trusted SQL Server connection.
Any idea to solve my problem ?
Thank you very much
See jTDS FAQ http://jtds.sourceforge.net/faq.html
you will have to pass useNTLMv2=true and domain=yourdomain
What you can do is something like:
String url = "jdbc:jtds:sqlserver://MYPC/MYDB;instance=SQLEXPRESS";
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(url);
Make sure you have jtds.jar in the Java build path.
Also, add "-Djava.library.path="PATH\JTDS\x64\SSO" where 'Path' is where your SSO folder is after installing the JTDS driver (this is where you have your ntlmauth.dll).
Here is a short step-by-step guide showing how to connect to SQL Server using jTDS (as well as JDBC) with Windows authentication should you need more details. Hope it helps!
The application I'm using tries to connect SQL Server named instance running on a dedicated database server. Here's the error I'm getting:
The TCP/IP connection to the host <instance_name>, port 1433 has failed. Error: Connection refused: connect.
Is the firewall blocking my access or what? Should I dedicate a different port for this application?
The error refused connect implies that your connection does not have permissions to connect to this instance of SQL Server.
Are you using Windows Authentication or a SQL Server Login?
For troubleshooting guidelines see: Troubleshooting Server and Database Connection Problems