Problem with Connection to SQL Server via Servlet (in iPlanet 6 App Server)

Hi ,

I am using the iPlanet ApplicationServer 6.0 SP2 for development & testing of an internet application.

I am facing a problem when I am trying to connect to MS SQL SERVER via the native jdbcodbc driver (obdc32.dll). The error is something like this :

[26/Jul/2001 11:50:35:7] warning: DriverConnect: (28000): [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '\'.(DB Error: 18456)

[26/Jul/2001 11:50:35:7] warning: ODBC-027: CreateConn: failed to create connection [new connection]: DSN=fadd,DB=cashbook,USER=test,PASS=xxxxxxxxx

[26/Jul/2001 11:50:35:7] error: DATA-108: failed to create a data connection wit

h any of specified drivers

Error in connecting to the Database for cirrus :java.sql.SQLException: failed to

create a data connection with any of specified drivers

java.sql.SQLException: failed to create a data connection with any of specified

drivers

at com.netscape.server.jdbc.Driver.afterVerify(Unknown Source)

at com.netscape.server.jdbc.Driver.connect(Unknown Source)

at com.netscape.server.jdbc.DataSourceImpl.getConnection(Unknown Source)

at gefa.util.DBConnection.jdbcConnectionOpen(DBConnection.java:65)

at gefa.servlet.ServUpload.doPost(ServUpload.java:45)

at gefa.servlet.ServUpload.doGet(ServUpload.java:29)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)

at com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown

Source)

at com.netscape.server.servlet.servletrunner.ServletRunner.execute(Unkno

wn Source)

at com.kivasoft.applogic.AppLogic.execute(Unknown Source)

at com.kivasoft.applogic.AppLogic.execute(Unknown Source)

at com.kivasoft.thread.ThreadBasic.run(Native Method)

at java.lang.Thread.run(Thread.java:479)

--

I have configured a DSN with the name "fadd" on the machine with the application server and it used NT authentication. I have supplied an NT userid and password that has appropriate rights on the database "cashbook".

When I write a java standalone program, it does connect but via a servlet it does not connect.

Can some guide me with this problem please ?

Anything one might have observed in the past ? (may be specific to iPlanet ?)

Thanks a lot in advance

~Sunil

[2474 byte] By [srmenon] at [2007-9-26 2:02:17]
# 1

I'm using iPlanet App server as well and experiencing similar problem. I load my SQL Server driver by Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"), then use DriverManager.getDriver() to obtain the Driver.

However, the Driver returned is not the SQLServerDriver as expected. The Driver returned is com.netscape.server.jdbc.Driver! And then when I do Driver.getConnection("jdbc:microsoft:sqlserver://MyServer"), it throws an SQLException saying that it doesn't accept a jdbc:microsoft:sqlserver subprotocol. Well, of course it doesn't, it's not a microsoft Driver at all.

I suspect the problem is that the netscape Driver's acceptsURL() method ALWAYS returns true in iPlanet app server, thus when you getDriver(), the netscape Driver is always returned (and always returned as the first one since it's default?). Thus even though the same piece of code works fine as a standalone application, it just doesn't work on iPlanet app server.

My work around is:

/*************************************************************/

Class.forName("my.Driver");

Enumeration enu = DriverManager.getDrivers();

Driver useThis = null;

while (enu.hasMoreElements()) {

Driver d = (Driver)enu.nextElement();

if (d.getClass().toString().indexOf("my.Driver") > -1) {

useThis = d;

}

}

/*************************************************************/

Mind that my above code does not have an performance issue. If you look into the source code of how DriverManager get a Driver for a particular URL, it also loads the whole set of available Drivers, then call acceptsURL() method on each of them to find the first "suitable" one. Thus time complexity is the same.

I know this is not a very elegant solution and it defeats the purpose of having a DriverManager. Does any one else has a better way to solve this problem, like a way to specify the priority of each Driver so that SQLServerDriver is returned before the netscape Driver?

Thanks a lot.

looksly at 2007-6-29 8:43:36 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...