MS SQL connection | Selenium Forum
M
Posted on 28/12/2015
Hi team i am trying to connect MS Sql in eclipse
below my code:
...........................................................................
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

Connection con = null;
try{
String server = "localhost\\sqlexpress";
int port = 49208 ;
String user = "emtuser"; // Sql server username
String password = "emt@123";
String database = "EMTR6_SIT";

String conUrl = "jdbc:sqlserver://"+server+":"+port+";user="+user+";password="+password+";databaseName="+database+"";

con = DriverManager.getConnection(conUrl);
--------------------------------------

BUt i am getting below error in console:
# - Driver Loaded
Error : com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 49208 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".


Please help

Thanks
Manoj

M
Replied on 28/12/2015

it cannot connect to the server

chk firewall.


M
Replied on 29/12/2015

I tried different code by setting the creating default DSN
---------------------------
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("# - Driver Loaded");
Connection con = DriverManager.getConnection("jdbc:odbc:login_DSN");
System.out.println("# - Drivermanager Loaded");
Statement s = con.createStatement();
-------------------------------
But i got this error
--------------------------------------
# - Driver Loaded
Error : java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][DBNETLIB]General network error. Check your network documentation.


M
Replied on 29/12/2015

[quote:2bzyi4b4]General network error. Check your network documentation[/quote:2bzyi4b4]

its giving a network error the problem is not with the code but the network.