Home > Archive > SQL Server JDBC > October 2005 > Using JDBC for SQLExpress









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Using JDBC for SQLExpress
Chandresh

2005-10-20, 8:24 pm

Has anyone used the JDBC driver for SQL Server 2005 to access a SQLExpress
database? Could you please share how did you configure SQLExpress to be able
to do this? What connection string did you use?
Angel Saenz-Badillos[MS]

2005-10-20, 8:24 pm

There are a couple of things to keep in mind when using Sql Express with the
JDBC driver:
· You need to enable mixed mode security when you install the server
so that you can connect using user name and password.
· The JDBC provider only works with the TCP/IP protocol which is
disabled by default on Sql Express. You need to enable the TCP/IP Protocol
from the SQL Server Configuration Manager that ships with SqlExpress and
re-start the server. Look under SQL Server 2005 Network Configuration ->
Protocols for SQLEXPRESS-> TCP/IP->Enable.

Once you have set up Sql Express accordingly you can connect like this:

import java.sql.*;

public class test{
public static void main(String[] args) {
try{
java.lang.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection c =
java.sql.DriverManager.getConnection("jdbc:sqlserver:// localhost\\SQLEXPRES
S;user=myuser;passwo
rd=mypass;");
System.out.println("Connected!");
}catch(Exception ex){
ex.printStackTrace();
}
}
}





--
Angel Saenz-Badillos [MS] DataWorks
This posting is provided "AS IS", with no warranties, and confers no
rights.Please do not send email directly to this alias.
This alias is for newsgroup purposes only.
I am now blogging: http://weblogs.asp.net/angelsb/




"Chandresh" < Chandresh@discussion
s.microsoft.com> wrote in message
news:F7F63D04-20D7-4194-9CD3- 18310E3EE941@microso
ft.com...
> Has anyone used the JDBC driver for SQL Server 2005 to access a SQLExpress
> database? Could you please share how did you configure SQLExpress to be
> able
> to do this? What connection string did you use?



Chandresh

2005-10-20, 8:24 pm

Thanks for the response. That did not work. I tried out the sanple code and I
get the following exception:

Failed Logon:com.microsoft.sqlserver.jdbc.SQLServerException: Failed
connection to named instance [sqlexpress] [java.net. SocketTimeoutExcepti
on:
Receive timed out] Error Code = 0
com.microsoft.sqlserver.jdbc.SQLServerException: Failed
Logon:com.microsoft.sqlserver.jdbc.SQLServerException: Failed connection to
named instance [sqlexpress] [java.net. SocketTimeoutExcepti
on: Receive timed
out]
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown
Source)
at java.sql.DriverManager. getConnection(Driver
Manager.java:525)
at java.sql.DriverManager. getConnection(Driver
Manager.java:193)
at SQLXJdbcTest.main(SQLXJdbcTest.java:10)


"Angel Saenz-Badillos[MS]" wrote:

> There are a couple of things to keep in mind when using Sql Express with the
> JDBC driver:
> · You need to enable mixed mode security when you install the server
> so that you can connect using user name and password.
> · The JDBC provider only works with the TCP/IP protocol which is
> disabled by default on Sql Express. You need to enable the TCP/IP Protocol
> from the SQL Server Configuration Manager that ships with SqlExpress and
> re-start the server. Look under SQL Server 2005 Network Configuration ->
> Protocols for SQLEXPRESS-> TCP/IP->Enable.
>
> Once you have set up Sql Express accordingly you can connect like this:
>
> import java.sql.*;
>
> public class test{
> public static void main(String[] args) {
> try{
> java.lang.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
> Connection c =
> java.sql.DriverManager.getConnection("jdbc:sqlserver:// localhost\\SQLEXPRES
S;user=myuser;passwo
rd=mypass;");
> System.out.println("Connected!");
> }catch(Exception ex){
> ex.printStackTrace();
> }
> }
> }
>
>
>
>
>
> --
> Angel Saenz-Badillos [MS] DataWorks
> This posting is provided "AS IS", with no warranties, and confers no
> rights.Please do not send email directly to this alias.
> This alias is for newsgroup purposes only.
> I am now blogging: http://weblogs.asp.net/angelsb/
>
>
>
>
> "Chandresh" < Chandresh@discussion
s.microsoft.com> wrote in message
> news:F7F63D04-20D7-4194-9CD3- 18310E3EE941@microso
ft.com...
>
>
>

Angel Saenz-Badillos[MS]

2005-10-21, 1:23 pm

The exception that you are seeing indicates that we were not able to get the
portnumber for the SQLEXPRESS instance. We retrieve the port number by
sending a DatagramPacket to port 1433 of the server you specified, for some
reason this is taking longer than 5000ms to complete.

Can you think of anythign that may be affecting this? my first guess would
be that the SQL Server Browser is not running, you can check the status of
this service in the SQL Server Configuration Manager that installed with Sql
Express under SQL Server 2005 Services -> SQL Server Browser->start.

If this is not the problem my second guess would be an issue with a
firewall.

--
Angel Saenz-Badillos [MS] DataWorks
This posting is provided "AS IS", with no warranties, and confers no
rights.Please do not send email directly to this alias.
This alias is for newsgroup purposes only.
I am now blogging: http://weblogs.asp.net/angelsb/




"Chandresh" < Chandresh@discussion
s.microsoft.com> wrote in message
news:2570580E-1DFE-43A3-8B59- 9049531ADB04@microso
ft.com...[color=darkred]
> Thanks for the response. That did not work. I tried out the sanple code
> and I
> get the following exception:
>
> Failed Logon:com.microsoft.sqlserver.jdbc.SQLServerException: Failed
> connection to named instance [sqlexpress]
> [java.net. SocketTimeoutExcepti
on:
> Receive timed out] Error Code = 0
> com.microsoft.sqlserver.jdbc.SQLServerException: Failed
> Logon:com.microsoft.sqlserver.jdbc.SQLServerException: Failed connection
> to
> named instance [sqlexpress] [java.net. SocketTimeoutExcepti
on: Receive
> timed
> out]
> at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown
> Source)
> at java.sql.DriverManager. getConnection(Driver
Manager.java:525)
> at java.sql.DriverManager. getConnection(Driver
Manager.java:193)
> at SQLXJdbcTest.main(SQLXJdbcTest.java:10)
>
>
> "Angel Saenz-Badillos[MS]" wrote:
>


Chandresh

2005-10-21, 1:23 pm

Couple of setting changes fixed this. The TCP/IP protocol was set to use
dynamic port (I'm not using the SQL Browser yet). I changed it to use a
static port and then using the 'SQL Server Surface Area Configuration' I
enabled TCP/IP for local and remote connection.

I had to specify the port number in the connection string and the program's
working now.

Thanks for your help.

"Angel Saenz-Badillos[MS]" wrote:

> The exception that you are seeing indicates that we were not able to get the
> portnumber for the SQLEXPRESS instance. We retrieve the port number by
> sending a DatagramPacket to port 1433 of the server you specified, for some
> reason this is taking longer than 5000ms to complete.
>
> Can you think of anythign that may be affecting this? my first guess would
> be that the SQL Server Browser is not running, you can check the status of
> this service in the SQL Server Configuration Manager that installed with Sql
> Express under SQL Server 2005 Services -> SQL Server Browser->start.
>
> If this is not the problem my second guess would be an issue with a
> firewall.
>
> --
> Angel Saenz-Badillos [MS] DataWorks
> This posting is provided "AS IS", with no warranties, and confers no
> rights.Please do not send email directly to this alias.
> This alias is for newsgroup purposes only.
> I am now blogging: http://weblogs.asp.net/angelsb/
>
>
>
>
> "Chandresh" < Chandresh@discussion
s.microsoft.com> wrote in message
> news:2570580E-1DFE-43A3-8B59- 9049531ADB04@microso
ft.com...
>
>
>

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com