Welcome to MSDN Blogs Sign in | Join | Help

Microsoft JDBC Driver Team Blog

Discussions related to Microsoft JDBC driver.
Welcome to the SQL Server JDBC blog

Unsure of what to specify in the connection URL? Having trouble configuring the driver for Integrated Authentication? Confused about some behavior with the Microsoft SQL Server JDBC driver? Then, this is the blog site for you.

The SQL Server JDBC team maintains this blog.  The team is responsible for all things regarding JDBC with SQL Server.  We hope to use this blog to proactively provide answers to many of the re-occuring issues that we see our customers face.  We will also use this blog to provide some insight into features in planning for future releases.

Hopefully you will find this useful.

SQL Server JDBC team
Disclaimer: This posting is provided "AS IS" with no warranties, and confers no rights

Posted: Tuesday, April 24, 2007 6:10 PM by dpblogs

Comments

Kris said:

Glad to see this. I would like to use JPA (Java Persistence API from Hibernate) with SQL Server Express edition. Wondering if you guys can provide any information with regard to this.

Thanks.

# April 24, 2007 10:52 PM

dpblogs said:

We are a hibernate ceritified driver. YOu should use SQLServerDialect in the configuration see: http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.html

Let me know if there is anything specific you want to know.

Thanks

Mugunthan

# May 9, 2007 4:32 PM

Berik said:

I have a password protected database. How can I connect to it via JDBC? In what connection parameter I must send database password?

# June 25, 2007 8:57 AM

Yesim said:

Hi,

Before we can answer your question, we need to know which SQL Server Edition you are using. Could you please clarify?

Thanks!

Yesim [MSFT]

# June 25, 2007 4:02 PM

steve.lloyd said:

I've been trying to configure Tomcat 6.0 to use the SQL Server 2005 JDBC Driver to access SQL Server 2005 through a jndi provided DataSource.

I am converting from programmatic creation of a Connection to using a DataSource to obtain a Connection.

I'm using the following per web application WEB-INF\context.xml:

<Context path="/eclipse" docBase="eclipse" debug="5" reloadable="true" crossContext="true">

   <Resource

       name="jdbc/orpsMirror"

       auth="Container"

       type="com.microsoft.sqlserver.jdbc.SQLServerDataSource"

       username="user"

       password="pass"

       driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"

       url="jdbc:sqlserver://PN1236318.lanl.gov"

       validationQuery="select 1"

       maxActive="10"

       maxIdle="2"

   />

</Context>

and the following WEB-INF\web.xml fragment

...

   <resource-ref>

       <description>SQL Server</description>

       <res-ref-name>jdbc/orpsMirror</res-ref-name>

       <res-type>com.microsoft.sqlserver.jdbc.SQLServerDataSource</res-type>

       <res-auth>Container</res-auth>

   </resource-ref>

...

When i execute something like the following code,

...

           ctx = new InitialContext();

           Object object;

           object = ctx.lookup("java:comp/env/jdbc");

...

I get the following STDOUT log message

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

Can you tell me how to configure Tomcat to allow servlets and JSP pages to access SQL Server? This has been somewhat frustrating.

Thanks.

# September 12, 2007 7:42 PM

Eric Marquez said:

Hello. I'm developing my application in Sun Java Studio Creator and Sun AppServer 8.2. I have this application that uploads pdf files to the database. With SQLServer 2000 it works, but now I'm using the same application to upload files to SQLServer 2005 and it doesn't work. Is there any property or something else that I must set in the database in order to do this? Thanks in advance.

Eric.

# September 24, 2007 4:50 PM

Eric Marquez said:

Sorry, I forgot to mention in my previous post that I'm using the latest JDBC driver (sqljdbc.jar v1.2.2727).

# September 24, 2007 4:53 PM

asaxton said:

Hello Steve,

The issue I believe you are hitting is your Context is not complete.  I've seen this done one of two ways:

1.  Grab the environment first, and then grab the datasource

// Grab the Environment first

object = ctx.lookup("java:comp/env");

// Now grab the DataSource

DataSource ds = (DataSource)ctx.lookup("jdbc/orpsMirror");

2. Grab the DataSource from the get go

// Grab the DataSource with the full path from the Environment

DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/orpsMirror");

I believe yours was failing because it was just looking for an element called "jdbc" which didn't exist.

Hope that helps!

Thanks,

Adam [MSFT]

# October 4, 2007 10:07 AM

asaxton said:

Correction to the first code segment I posted.  It should be:

// Grab the Environment first

Context envCtx = (Context)ctx.lookup("java:comp/env");

// Now grab the DataSource

DataSource ds = (DataSource)envCtx.lookup("jdbc/orpsMirror");

# October 4, 2007 10:11 AM

tfan@kronos.com said:

Hi,

  We are evaluating JDBC v1.2 and found out there is different with getBytes Method (SQLServerResultSet) call getBytes Method (SQLServerResultSet)

this is output when I tried two drivers:

using JDBC v1.1

Timestamp from DB is: 2007-10-26 12:45:45.9

byte array is:

0 is -45

1 is -103

2 is 0

3 is 0

4 is -38

5 is 82

6 is -46

7 is 0

using JDBC v1.2

Timestamp from DB is: 2007-10-26 12:44:42.04

0 is 0

1 is 0

2 is -103

3 is -45

4 is 0

5 is -46

6 is 8

7 is 4

you can see first 4 elements values have been changed (with different order).  can someone provide more information about this? Thanks.

--Tony

# October 26, 2007 3:19 PM

Amalia said:

Hola actualice el sqljdbc 1.1 por la vesion 1.2 y al ejecutar cualquier consulta me da este error com.microsoft.sqlserver.jdbc.SQLServerException: La instrucción no devolvió un conjunto de resultados.

Si me pudieran ayudar con esto... Gracias

# February 7, 2008 12:35 PM

Mugunthan said:

Can you provide a sample that is failing?

Thx

¿Puede usted proporcionar una muestra que falla?

# February 7, 2008 4:49 PM

Rohit Gupta said:

I'm using Tomcat 5.5, J2SDK 1.4 and I want to access my db at MS SQL Server 2000. I'm getting error as

"Following error/exception occured - java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Unsupported method: ResultSet.isAfterLast at"

Also

Following error/exception occured - java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Unsupported method: ResultSet.setFetchDirection at

Any help???

# February 14, 2008 7:10 PM

Mugunthan said:

Can you try the SQL 2005 JDBC Driver, this supports SQL 2000 server as well.

# February 27, 2008 5:18 PM

Diana said:

Hi Everyone,

Does anyone know if it is possible through JDBC connection to have the loginto  SQL server automatically authenticate through AD(Active Directory - windows login, instead of entering a user name and password.) similar to single sign on.

If possbile, how? Can anyone direct me to any documentations, etc?

Thanks

# April 9, 2008 4:04 PM

Ray said:

I have the same question as Diana above.  Does anybody have a response for this?   Diana,  were you able to get an answer outside this blog?

# April 15, 2008 10:12 AM

Ashish Gupta india said:

i am having an issue while using JDBC driver to connect to MSSQL2000 server

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3199367&SiteID=1

# April 21, 2008 2:39 AM

Jeff said:

I'm trying to connect with integrated security using the 2005 JDBC driver. Here is the error message:  Error creating JDBC Connection to RLID.

(Error: This driver is not configured for integrated authentication.)  I've installed sqljdbc_auth.dll in my Eclipse folder, and in the windows/system32 folder.  I don't have any problems connecting with Windows Authentication using SQL Management Studio.  Intermittently, the connection will succeed even after throwing the error message.

# May 1, 2008 5:10 PM

Colby said:

I am trying to  connect Sun Application Server 8 to MS SQL 2005.  I can currently connect to SQL 2000 just fine and I am wondering if there are any differences that need to be taken into account -- Class Names, Resource Types, etc.

thx

# July 1, 2008 11:18 AM

Colby said:

I am trying to  connect Sun Application Server 8 to MS SQL 2005.  I can currently connect to SQL 2000 just fine and I am wondering if there are any differences that need to be taken into account -- Class Names, Resource Types, etc.

thx

----

(Sorry I forgot this) I am currently getting this error when trying to Ping using a connection pool:

Operation 'pingConnectionPool' failed in 'resources' Config Mbean. Target exception message: Connection could not be allocated because: Network error IOException: Connection refused: no further information

# July 1, 2008 11:20 AM

dpblogs said:

Hi Colby,

Which JDBC driver are you currently using to connect to SQL Server 2000?

If you are already using the SQL Server 2005 JDBC driver then you only need to point the application to SQL Server 2005.

If you are using a different driver you will need to update the class name.  An simple example would look like:

 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

 String connectionUrl = "jdbc:sqlserver://localhost;database=AdventureWorks;integratedSecurity=true;"

 Connection con = DriverManager.getConnection(connectionUrl);

Regarding the exception you are getting, I would recommend that you try to create a standalone application outside of the Sun Application Server 8 to make sure you have the right connection string and application settings to connect to SQL Server 2005.

You will also want to make sure SQL Server 2005 is properly configured to listen to remote TCP connections.  The typical TCP port that SQL Server 2005 listens on is 1433.  Make sure that the Windows OS firewall on SQL Server 2005 machine is not blocking the TCP port.

If SQL Server 2005 is installed as a named instance and you are specifying the instance name on the connection string, please make sure the SQLBrowser service is running on the SQL Server 2005 machine and Windows firewall is not blocking UDP 1434.

HTH,

Jimmy Wu

# July 1, 2008 7:11 PM

roger b said:

I cannot access SQL Server 2K5 through eclipse or through the command line using sqlcmd or osql. I keep getting connection refused. I'm on Vista Ultimate working locally. Management Studio gets through perfectly of course because it is Microsoft technology made to work perfectly with Microsoft technology: seamlessly, flawlessly and magically. Everything else (non-Microsoft technology)takes forty-seven hours of configuration and hacking.

# July 24, 2008 6:58 PM

Mugunthan Mugundan -MSFT said:

Can you say what error you are seeing? Also, have tried the steps provided by Jimmy above.

# July 24, 2008 7:08 PM

roger b said:

FROM T-SQL:

C:\Users\Roger Blackmar>osql -U jboss

Password:

[SQL Native Client]Named Pipes Provider: Could not open a connection to SQL

Server [2].

[SQL Native Client]Login timeout expired

[SQL Native Client]An error has occurred while establishing a connection to

the server. When connecting to SQL Server 2005, this failure may be caused by

the fact that under the default settings SQL Server does not allow remote

connections.

# July 24, 2008 8:02 PM

roger b said:

FROM Eclipse:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host  has failed. java.net.ConnectException: Connection refused: connect

at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)

at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)

at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)

at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)

at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)

at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.createConnection(JDBCConnection.java:89)

at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:104)

at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:53)

at org.eclipse.datatools.enablement.msft.internal.sqlserver.connection.JDBCSQLServerConnectionFactory.createConnection(JDBCSQLServerConnectionFactory.java:27)

at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)

at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:355)

at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)

at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)

at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

# July 24, 2008 8:02 PM

roger b said:

It is not getting to the authentication handshake it is refusing the connection, outright. Management Studio connects immediately without a problem.

# July 24, 2008 8:04 PM

dpblogs said:

Hi Roger,

You mentioned that you are working locally, is SQL Server configured with TCP enabled?

For security reasons, by default SQL Server does not enable remote TCP/IP or Named Pipe connection support when initially installed.  This may explain why both Eclipse and OSQL can not connect to SQL Server, while the Management Studio application can.

Please double check the configuration of SQL Server and also please post the connection URL you are using to connect to SQL Server.

HTH,

Jimmy

# July 24, 2008 9:06 PM

roger b said:

Thank you for responding. I resolved the issue by un/reinstalling SQL Server 2005.

I noticed when reinstalling that there are some IIS 7 components on Vista (same for Server 2008) that you have to manually install through "Turn Windows features on or off". Here is the info for that:(http://learn.iis.net/page.aspx/28/installing-iis-70-on-windows-vista)

It is working perfectly now in Eclipse.

# July 24, 2008 11:50 PM

raj said:

if any one know about this thing that windows authentication is possible using hibernate for mssql 2005 please give me the information how i will change my hibernate config file i used jtds

hibernate.cfg file

<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE hibernate-configuration PUBLIC

"-//Hibernate/Hibernate Configuration DTD//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory name="java:comp/env/hibernate/SessionFactory">

     <property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>

     <property name="hibernate.connection.url">jdbc:jtds:sqlserver://192.168.11.22:1433;databaseName=eventsdb;integrated security=true</property>

     <property name="hibernate.connection.username"></property>

     <property name="hibernate.connection.password"></property>

     <property name="hibernate.connection.pool_size">10</property>

     <property name="connection.autocommit">false</property>

     <property name="show_sql">true</property>

     <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>

      <mapping resource="esq/connector/dataobjects/user.hbm.xml"/>

</session-factory>

</hibernate-configuration>

and i copy all the jar file jtds.jar and native jar or ntlmauth.dll file in system32 or i have given the path in enviroment variable also..i have done all the thing carefully but still

i am getting error

"Login failed for user ''. The user is not associated with a trusted SQL Server connection."

# September 2, 2008 7:48 AM

raj said:

if u got any solution plz reply me my id

EMAIL ME:-raj1112@oneindia.in

# September 2, 2008 8:25 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker