Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JDBC-ODBC - problems with connecting to SQL Server..

Status
Not open for further replies.

sm43

Programmer
Dec 1, 2002
155
US
Hi,
Not sure if this message belongs here or in 'SQL Server'.

I'm trying to connect to a SQL Server database through a JDBC-ODBC driver. I have the database registered in the ODBC Control Panel under System DSN. I'm using SQL Server Authentication and have a userid and a non-blank password. For some reason, everytime I register the DSN in ODBC, it tests successfully, but the password for the DSN disappears immediately after I 'OK' the ODBC DSN registration. I'm running Windows 2000 Professional and the database is SQL Server 2000. I've just read somewhere that the ODBC Panel won't save the password. You have to pass it in the url. Is this true? Well, anyway, I include the uid and the password in my connection string. I have the following connection url:

"jdbc:eek:dbc:DSNName;UID=user;PWD=pass"

When I do it this way, and run the Java program I get the following error:

java Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.


Do I have to pass the trusted connection information (i.e. whether the connection is to be trusted or not) in the connection url as well?

Also, when I try Windows Authentication in the ODBC Panel, the java progam connects to the SQL Server database, but when it runs a query, it gets the following error:

"Invalid Descriptor Index"

and then,

"Connection is busy with results for another hstmt"

on every subsequent query attempt.

I have no idea what these mean?

The user I'm using to login is given owner rights for the db in SQL Server. It is given no Server Roles.


What's going on? It seems like I'm missing a couple of things here. How can I solve this?

By the way, I've implemented and tested the whole application with MS Access 2000 db and none of these problems occur with that. In MS Access, I don't have any serious authentication, i.e. no userid and password..

Thanks.

Saad
 
you can specify the user and password as parameters of the connection object. I think user and password in the DSN are ignored.

Trusted connection is for Windows only. So, I think it's not possible to work with it in Java.

Thomas ---
A free GUI for your database:
 
ok, yes! passing uid and pass with the jdbc connection object did solve the problem. However, I was still getting the

"Invalid Descriptor Index"

error. I went hunting on the web and vaguely read somewhere that the problem had to do with the version of JDBC you were using. Don't know for sure if JDBC version indeed is the root of the problem, but the problem is solved if you access the Recordset fields in the order that you retrieved them from the table. e.g.

Select id, name, descrip from MyTable

should be accessed as follows:

idTemp = rs.getInt("id");
nameTemp = rs.getString("name") ;
descripTemp = rs.getString("descrip") ;


if you do:

nameTemp = rs.getString("name") ;

then,
idTemp = rs.getInt("id");

you'll get the error..


Thanks.
Saad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top