Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the difference between Java and C# when it comes to connect to Sql Server Database?
    primarykey
    data
    text
    <p>I am writing an application requires to connect to sql server. I prefer to write the App in Java. but When I try to connect to the server I got the connection refused error. I am using JTDS JDBC driver. I think it is due to the port 1433 or 1434 are not open. The server is in my work place and I can not change the ports. But funny enough, I use c# writing the same thing, it connects successfully. is it because SqlConnection class in C# library works better with ms sql server? or am I doing something wrong here? FYI, the server we are using in work is MS SERVER 2003.</p> <p>Sorry I did not provide any code earlier. One tricky part is that the server we have is called "SERVER" on the local network.</p> <p>C#:</p> <pre><code>SqlConnection objConnection = new SqlConnection("Data Source= SERVER\\SQLEXPRESS;Initial Catalog=SSS;Persist Security Info=True;User ID=user;Password=pass"); SqlCommand objcommand = new SqlCommand(); string strSQL; objcommand.Connection = objConnection; strSQL = "select * from company where companyid = @companyID "; try { objConnection.Open(); SqlDataReader Query = objcommand.ExecuteReader(); while (Query.Read()) { MessageBox.Show(Convert.ToString(Query["clientRef"])); } objConnection.Close(); } catch (Exception ex) { MessageBox.Show("Error Retreiving info: " + ex.ToString(), "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error); objConnection.Close(); } </code></pre> <p>As I am not really familiar with C#. I have got the code above from one of the colleges. and it returns the info correctly.</p> <p>Java:</p> <pre><code>try{ Connection connection; Class.forName("net.sourceforge.jtds.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:jtds:sqlserver://network.local/SERVER\\SQLEXPRESS:1433/SSS","user","pass"); System.out.println("Connection succeed!"); } catch (Exception e) { e.printStackTrace(); } </code></pre> <p>The java code above got Network error IOException: Connection refused error. FYI: I can ping server.network.local successfully. But when I telnet server.network.local 1433/1434, I got telnet: Unable to connect to remote host: Connection refused.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload