Link to home
Start Free TrialLog in
Avatar of pavelmed
pavelmed

asked on

SQL Server Express connection error (with Hibernate, Java-based web app, and Tomcat)

I am trying to resolve a database connection problem while trying to setup a Java-based web application.
There is a working Java-based web application (that uses Hibernate and MS SQL Server Express as a database, and Apache Tomcat as a web server).
I am trying to setup a copy of that web site on another computer (for development).
That another computer already has Apache Tomcat and the SQL Server Express installed, and I mad sure that both computers use the same version of Java.  
I backed up the database from the working site and restored it on the new machine.
Then I created the war file on the working machine and expanded it on the new machine.
I made sure the database's setup, configuration, and user's login info is identical on both machines.  The hibernate.properties files are identical on both machines (except the machine's name).
However the web application fails to be displayed, and Tomcat's log files show the database connection errors.that appear when the Tomcat service is being started, such as
"Login failed for user 'myUser'."
The hibernate.properties file contains these lines:
*************************************************************************************************
hibernate.connection.url=jdbc:jtds:sqlserver://XXXXXXX1:1433/musApp;instance=SQLEXPRESS
hibernate.connection.driver_class=net.sourceforge.jtds.jdbc.Driver
hibernate.connection.username=myUser
hibernate.connection.password=myPassword
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
*******************************************************************************************************
The errors from the catalina_xxx.log file are below (between the lines):
--------------------------------------------------------------------------------------------------------
May 28, 2009 12:38:53 PM org.hibernate.connection.ConnectionProviderFactory newConnectionProvider
INFO: Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
May 28, 2009 12:38:55 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 4060, SQLState: S1000
May 28, 2009 12:38:55 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Cannot open database "musApp" requested by the login. The login failed.
May 28, 2009 12:38:55 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 18456, SQLState: 28000
May 28, 2009 12:38:55 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Login failed for user 'musAdmin'.
May 28, 2009 12:38:55 PM org.hibernate.cfg.SettingsFactory buildSettings
WARNING: Could not obtain connection metadata
java.sql.SQLException: Cannot open database "musApp" requested by the login. The login failed.
--------------------------------------------------------------------------------------------------------
Could you please assist in resolving the problem?
Again, the application is working on another machine, and the setup is identical (at least, I cannot see the difference).



Avatar of pavelmed
pavelmed

ASKER

Forgot to mention: The database server is configured for "SQL Server and Windows Authentication mode".
Avatar of CEHJ
Can you telnet to that address and port from the machine you're trying to run it on?
I am trying to access the site locally, from the same machine.
I can use the working site also locally, from the working machine.
Both machines are development machines.
On the new machine, if I try to display the web site, it is starting but fails when it tries to use DB data.

I don't have telnet on that machine.
I don't know about SQLEXPRESS but on standard SQL Server, I have a similar Hibernate config, but I always have to enable the SQL Server TCP port first. I use "SQL Server Configuration Manager" from the start menu and under SQL Server Network Configuration, enable TCP/IP, then set Listen all and IPall to port 1433
MySql must have granted permissions to connect from the host (machine) you're currently connecting from.

http://dev.mysql.com/doc/refman/5.1/en/adding-users.html
Oops sorry  - wrong DB!. Nonetheless, make sure you have permission to connect from that host
I set it up exactly as on working machine: under SQL Server Network Configuration, enabled TCP/IP, and also enalbed TCP/IP under SQL Native Client Configuration.
1433 port is specified under SQL Native Client Configuration.- it is setup that way and works on another machine,
Your sqljdbc.jar (or whatever the source fource driver jar name is) is deployed with your web app or is it in Tomcat common lib?

It doesn't look like a missing jar, it looks like a permissions problems, but since I don't use that driver, I use the standard Microsoft one, I cannot say.
CEHJ, the user is setup as a database owner on that machine.

However, I would like to test a DB connection.
How can I test a DB connection?  The tool that I am using, the SQL Server Management Studio Express, uses a Windows authentication, so username and password are not needed to connect to the database
mrjoltcola, I am not sure about that driver.  it users the net.sourceforge.jtds.jdbc.Driver.  In catalina.log file I can see that tomcat loads the file.
I have resolved this error.
Administrator, please close this question.
Can you provide the solution for our benefit? :)

You normally close your own questions by either deleting or scoring a solution. If you found your own solution, it is good for EE if you post it and score it, and also helps the experts that spent time trying to assist you, for future knowledge purpose.
ASKER CERTIFIED SOLUTION
Avatar of pavelmed
pavelmed

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial