I successfully connected to my database when it was SQL Server 2008 R2.
However after upgrading to SQL Server 2012, I get the following error in my java code
The application server that I am using is Tomcat7
The error is as follows:
Jun 10, 2012 1:56:10 PM org.apache.naming.NamingContext lookup
WARNING: Unexpected exception resolving reference
com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database "MyDB" requested by the login. The login failed.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
The connection string in context.xml is
<Resource name="jdbc/theDB" type="javax.sql.DataSource" auth="Container"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" initialSize="30"
maxActive="100"
url="jdbc:sqlserver://localhost:1433;databaseName=MyDB;integratedSecurity=true"
/>
The following is in web.xml
<resource-ref>
<description>My Database</description>
<res-ref-name>jdbc/theDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
I can connect successfully to the database by opening a Data Connection in Eclipse, and in the fact the connection string that is generated is identical to the url from context.xml that I reproduce above.
Has anyone any ideas?
Thank you!
Make sure you the user that is running the application server has sufficient rights to the database.