Unable to connect with sql server with servlet.
its on tomcat 7 which says
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection ("jdbc:sqlserver://;integratedSecurity=true");
Getting error:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'MYDOMAIN\SUMIT-PC$'.
SUMIT-PC is my computer's name.
it should be 'MYDOMAIN\SUMIT SINGH'
This means that your tomcat is running under LocalSystem account in domain-based network. If you want to make tomcat to use your login propagation - you should to tune up it to impersonate logged on user and your tomcat and sql server(or workstation for windows 2003 domains) should be trusted for delegation on domain level, and user MYDOMAIN\SUMIT SINGH should be also not denied for delegation on domain level.
or
implement your own impersonation inside the server process - this requires you to know user's password
Today I got the same issue. In my machine, it was Tomcat 8.5 and I have installed tomcat as a windows service. (installed using apache-tomcat-8.5.40.exe)
Press the Win + R keys on your keyboard, to open the Run window. Then, type services.msc and hit Enter or press OK.
Right click on Tomcat service and select Properties. In that dialog box go to Log On tab and select This Account under Log on as option. Fill your username, password as well. Then click OK.
Then restart the service!!!
Related
I am trying to connect to the SQL Server database using Eclipse but it's giving me the error:
Cannot open database "AdventureWorks2012" requested by the login. The login failed.
Since you are using integratedSecurity=true it means that you windows account is not allowed to access AdventureWorks2012 database. You need to grant the Windows account you are logged in (or running Eclipse) the database access rights. You can follow To configure database access docs to grant your Windows account access:
On the computer that is running SQL Server, start SQL Server Management Studio. In the Registered Servers pane, double-click SQL Server.
In the object explorer pane, expand SQL Server, expand the Security folder, right-click Logins, and then click New Login.
In the Login – New dialog box, specify either Windows Authentication or SQL Server Authentication mode.
If you are using Windows Authentication, enter a logon name and select either the Grant Access or the Deny Access option.
If you are using SQL Server Authentication, type a logon name and password, and then confirm the password.
In the left pane, click Database Access.
In the right pane, select the Permit check box for the databases you are granting access to, and then click OK.
If you want to connect by specifying username and password use integratedSecurity=false and supply username and password as shown in the Establishing a Connection docs:
String jdbcUrl = "jdbc:sqlserver:...";
Properties props = new Properties();
props.put("user", <database username>);
props.put("password", <database password>);
try (Connection conn = DriverManager.getConnection(jdbcUrl, props)) {
...
}
I have a server on remote where i am logged by ssh. I have unzip it the glassfish v 3.1.2 and follow the steps http://bbissett.blogspot.com.es/2012/01/asadmin-with-remote-glassfish.html until the part where enters in the link of admin(port 4848) There I am redirect by the browser to the web where the login loader (ip-glassfish-installed:4848) starts spinning and nothing happens.
The log I got in the server is "User [] from host localhost does not have administration access|#]" But I have changed the admin password and login with it. So I dont understand in first instance why I got the user empty. Also, although I think is not related, says that the certificate has expired.
You need to enable remote adminstration. Here are couple of other useful links that provide help in that direction:
http://www.adam-bien.com/roller/abien/entry/enabling_remote_administration_for_glassfish
https://blogs.oracle.com/quinn/entry/securing_adminstration_in_glassfish_server1
The problem is that the user I logged in the remote machine by ssh did not have the right permission to execute the domain, even after doing "sudo su". If I enter in the remote machine with the root user everything works fine, or using "sudo su -" after login with the normal user.
I am using jTDS to connect a Liferay instance to an SQL Server 2008 Express server using the SQL Server authentication (instead of the Windows' auth method). I have something like this in my portal-ext.properties:
jdbc.default.driverClassName=net.sourceforge.jtds.jdbc.Driver
jdbc.default.url=jdbc:jtds:sqlserver://127.0.0.1:1433/somedb
jdbc.default.username=someuser
jdbc.default.password=somepassword
(For those that do not know Liferay, it is somewhat alike to call
Class.forName("net.sourceforge.jtds.jdbc.Driver");
con = DriverManager.getConnection("jdbc:jtds:sqlserver://127.0.0.1:1433/somedb",
"someuser", "somepassword");
However, although I pass the correct username and password, it keeps going wrong with the message Login failed for user 'someuser'. I am dead sure the server login, the database user and the database exists and are well configured.
What can be wrong?
Well, I suppose there can be infinite reasons for such an error. In my case, nonetheless, the solution was the following:
Enable the TCP/IP connection in SQL Configuration Manager.
Open the SQL Server Management Studio (if you do not have it installed, install it; it can have its own pitfalls, however).
Right-click on the database server (as in the picture below) and click in Properties.
Select the Security option and mark SQL Server and Windows authentication mode. Click in OK.
Open the SQL Server Configuration Manager and restart the SQL Server service.
After this, I got my connections without problems. This article helped me a lot.
I trying to test the connection with my local sql DB. I have this code:
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=SocialFamilyTree;user=SOSCOMP");
}catch(Exception e){
System.out.println("Couldn't get database connection.");
e.printStackTrace();
}
I tried many users. my windows user is SOSCOMP and doesn't have a password. I also know that SQL 2008 create users as "sys" "dbo", I tried these too. I'm always getting:
Couldn't get database connection.
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'SOSCOMP'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2532)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1929)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1917)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1061)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:243)
at FT_Receiver.FT_Receiver.main(FT_Receiver.java:12)
Any ideas?
Thanks
If you try to connect with database which is using windows authentication, you can use 'integratedSecurity' option in your connection string.
DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=SocialFamilyTree;integratedSecurity=true;");
Having been through this very recently the steps I took to solve pretty much the same problem were
use SQL Server Management Studio to log in with the desired account and confirm access to read (and write if necessary)
Use SQL Server Configuration Manager to confirm that the server instance is listening on the IP address being targetted
Disable the firewall to check that isn't getting in the way (and add an exception if necessary for future use)
The absolute kicker for me was understanding what IP addresses and ports the instance was set to listen on so that when I constructed the connection string the connection wasn't being rejected.
Also, if you want to connect using Windows logins you need to ensure the SQL instance is configured for mixed mode authentication (i.e. to allow Windows and SQL logins)
Since you get this error,the Sql server correctly listens to the port.
Open Sql Server Management Studio connect to your Server.
right click on the server's icon and choose properties.
Go to the security tab and tick Sql Server and Windows
Authentication mode.
If you want to define a user,go from the tree, to Security->Logins,right click on logins folder and click "New Login".
Now your server should work with this Url String.
Use the log file of the Server that may help you understand its working.
Re: Did it. still WARNING: Failed to load the sqljdbc_auth.dll cause :- no sqljdbc_auth in java.library.path – Mike Oct 7 at 14:03
you have to add the path to sqljdbc_auth.dll by adding this under VM arguments in Eclipse or commandline if you're running from the shell:
-Djava.library.path="\MS SQL Server JDBC Driver 3.0\sqljdbc_3.0\enu\auth\x86"
that's if you're running 32 bit Windows. else the final subdir changes accordingly.
I think this might be a better answer though, to setting up SQL Server user based authentication:
Connecting SQL Server 2008 to Java: Login failed for user error
(I try to summarize it here: http://silveira.wikidot.com/sql-server)
I also faced the same issue, In my case the following things are configured wrongly
Two SQL (versions) servers are running in my system --> Sol: Please check ourselves which server we are pointing.
Ports are configured as dynamic --> Sol: we should set port 1433 and dynamic port should be 0, if we are connected to specific port.
While creating the new login (user) I have selected the option " change password after first login "--> Sol: we should not select this option while creating the new login, if we are trying connecting from some other service like Openfire.
I am trying to connect my Java code to a Microsoft SQL Server 2008 R2 Express database. I have downloaded the Microsoft SQL Server JDBC Driver 3.0 and added the sqljdbc4.jar to my classpath. I am using Netbeans and have included the sqljdbc4.jar in my project also.
I created a database in the SQL Server Management Studio called TestDB1 and added some columns and values that I will use for testing. I changed from Windows Authentication Mode by right clicking on the server JACOB=PC\SQLEXPRESS->Properties->Secuity and changing from Windows Authentication Mode to SQL Server and Windows Authentication Mode.
I then created a new login by right clicking on the Login folder in the window explorer under JACOB-PC/SQLEXPRESS->Secuity Folder->Logins Folder and added a new login. I gave it the name jhaip2, switched to SQL Server authentication and the set the password to jacob. Enforce password policy and enforce password expiration are unchecked. The default database is set to TestDB1. Then under TestDB1->Secuity->Users->jhaip2->Database role membership I set jhaip2 to db_owner (I couldn't log in to the database in the management studio without doing this, probably not the right thing to do?). I then restarted the server.
Now for my java code, it is basically a direct copy of the JDBC Driver 3.0 Sample code except without windows authentication.
package databasetest1;
import java.sql.*;
public class connectURL {
public static void main(String[] args) {
// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost:1433;" + "databaseName=TestDB1;";
// Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("Driver okay");
con = DriverManager.getConnection(connectionUrl,"jhaip2","jacob");
System.out.println("Connection Made");
}
// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
}
}
When I run, it prints out "Driver okay" so I am assuming my driver is set up correctly. Then it prints the error:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'jhaip2'.
It does not matter what username I use, it always fails. I have a feeling I am setting up the user wrong. If anyone could give me some help on how to properly set up a user or any guidance in how to simply connect to a SQL Server database in Java, I would appreciate it.
run this query by selecting your database
CREATE LOGIN aaron792 WITH PASSWORD='12345'
USE BudgetAuthorization
CREATE USER aaron792
i use aaron792 you should use yours
In sql server management studio go to object explorer and right click on (local)(sql server xxx) then go to properties it will open server properties and then go to security and change server authentication mode from windows only to sql server or windows (2nd option)
USE [master]
GO
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2
GO
in server properties , go to permissions and select newly created user from Logins or rules list then below it check all options for grant in explicit rule
open SQL server configuration manager and -> sql server services
at top row SQL server right click and open properties then change built in account to Local System
then restart every thing and make sure it is running. then try your code
I know this has already being answered but would like to give a little twist to it without having to reinstall the whole SQLSERVER RDBMS.
The concept is to change the properties of the sqlserver instance you are trying to connect to.
Step one. Open SQL Management Studio and select the sql server instance from the object explorer.
Right click on the instance and select properties from the popup menu which will open a Server Property Window.
select Security option which is located at the right side of the page. Then change server authentication from Windows Authentication mode to SQL SERVER and Windows Authentication mode (mixed mode).
Select Permissions option afterwards. Then with Permissions selected, select the Login Account you would like to grant permission to. (Login Account should be created before this, check this tutorial out http://www.blackthornesw.com/robo/projects/blackthornepro/HOWTO_-_Creating_a_SQL_Server_Database_Login_Account.htm . The edition might be different from what you have but the concept or workflow remains the same.). Under the permissions, select the Explicit tab, and under Grant, select all the options.
Click OK.
Step Two: to configure the RDBMS to use the internally created Login Accounts. Therefore:
Open/Start SQLSERVER configuration Manager.
Select SQL SERVER Services from the left pane.
With that selected, move to the right pane and right click on SQL Server (MSSQLSERVER) option and then select properties from the popup menu.
SQL Server (MSSQLSERVER) properties window appears, make sure Log On tab is selected, then select the radio button named Built-in Account under Log on as: Option. Then select from the combo box, Local System.
Click OK. By clicking on ok, you will be asked to restart the instance, go ahead to restart it. If restart is not asked, then move to step three below.
Step Three: to restart the SQLSERVER RDBMS.
Go to Control Panel > Administrative Tools > Component Services.
Select Services from the left pane
Then select SQL Server (MSSQLSERVER) from the right pane, the click restart which is just a little to the top right side.
When I looked in the SQL Server log files, it was saying that I couldn't log in because SQL Server was in Windows Authentication mode, even though in the program it was set to Mixed Authentication Mode.
When installing, I had set it up in Windows Authentication mode but changing the settings in the program would not change it from Windows Authentication mode.
I removed SQL Server 2008 and all related programs from my computer and installed a fresh copy, this time with SQL Server Authentication. Everything works correctly now. I don't know why SQL Server had a problem with changing the authentication mode, but it works now so I am happy.
Would this other question possibly be the same issue: MS SQL Server 2005 Express x86 - its port is unreachable - help.
You have to make sure that SQL Server is listening on the correct port before you can connect via a TCP connection using JDBC.
I ran into the same issue. Thank you, jhaip, for pointing me to the right direction: SQL Server was in Windows Authentication mode.
I'd like only to add that it is not necessary to reinstall the SQL server and all related programs. What's just needed is to change authentication mode. See this answer for more details: An attempt to login using SQL authentication failed