Saturday, November 8, 2014

Connectiong to the MS SQL server from ubuntu platform

Hello every one,
   First of I need to admit this is possible and you just need not to change your dev environment if your ms sql database is hosted in a separate server which you can access.
The following are the assumptions 
  • You dev environment is ubuntu
  • You have hosted your ms sql server in a windows server machine, and withing the same network which can be accessed
  • You have the necessary libraries download

What can go wrong :
  • First of ping the server from your ubuntu terminal and see whether you can access the server ping 192.168.XX.XX 
  • Then get the username and password of the ms sql user
  • Make sure you use the correct lib or the maven repo( please see the library or maven repo details below.

In my example I am using jtds-1.3.1.jar, so download the aforementioned .jar file, or if you are using maven repo use the below.


     <dependency>
            <groupId>net.sourceforge.jtds</groupId>
            <artifactId>jtds</artifactId>
            <version>1.3.1</version>
        </dependency>


Version could change as this is posted on 2014/11/08

Further you can use another type four lib such as sqljdbc4.jar yet I wnt be using that for my example.

Once your checked the above conditions make the connection string as follows.

jdbc.url=jdbc:jtds:sqlserver://192.168.22.12:1433;databaseName=jobs

The general string would be
jdbc.url=jdbc:jtds:sqlserver://<server ip or the name>:<port number>;databaseName=<name of the database>

And the driver class for this would be
net.sourceforge.jtds.jdbc.Driver

further if you want you can state the username and the password in the connection string.


Further, there is an old way which is almost deprecated by now. Thats is to use the following three libraries.

I used this to connect the win server 2005/2000.

Windows authentication will not work for ubuntu, so my advice is only use the SQL Authentication. You can use windows authentication in windows machine.


please let me know if you need more infor. I am happy to help


rashendra@gmail.com

Rashen






No comments:

Post a Comment