Page 1 of 2 12 LastLast
Results 1 to 20 of 34
  1. #1
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    4

    Default Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionException

    The full exception description:
    Java Code:
     org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host COMPUTERNAME (<<OSK-.......DE3>>), port 2461 has failed. Error: "connect timed out. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port."
    .
    In case I define Localhost and port:1433 -- the exceprt would be
    Java Code:
    The TCP/IP connection to the host localhost, port 1433 has failed
    My Spring-servlet configuration:
    Java Code:
    <bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
          <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
          <property name="url" value="jdbc:sqlserver://OSK-.......DE3\MSSQLSERVER:2461" />
         <property name="username" value="" />
          <property name="password" value="" />
       </bean>
    The same happens when I define url as:
    <property name="url"
    value="jdbc:sqlserver://OSK-.......DE3\MSSQLSERVER:2461;databaseName=db1t;inte gratedSecurity=true;"
    or <property name="url"
    value="jdbc:sqlserver://OSK-.......DE3\MSSQLSERVER:2461;databaseName=db1;" (my 127.0.0.1 sqlserver service works on 2461 port).
    I do understand that the reason probably in url, as firewall is disabled.
    I use sqljdbc4-2.0.jar; spring-jdbc-3.2.3.jar; spring-dao-2.0.6.jar;
    Should I include some java-path to my db1 folder location?
    Where to find decision?
    I cannot use MS Server configuration manager as said here: java - ms sql configuration in beans.xml - Stack Overflow -- as it throws error --"Cannot connect to WMI supplier" -- Server is inaccesible or has no access.
    Cannot find this module -- [0x8007007e].
    Indeed msserver4 and management studio 2008 works seems to be well.
    One forum topic for such error type suggests to change
    "jdbc:sqlserver://OSK-.......DE3\MSSQLSERVER:2461" />
    to "jdbc:sqlserver://OSK-.......DE3\\MSSQLSERVER:2461" /> (doubling the slash) -- but in my case -- in vain.
    Last edited by ark; 03-27-2017 at 02:28 AM.

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,951
    Rep Power
    7

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    SQL Server runs on port 1433 by default. Are you really, really sure that the server uses that other port? And are the username and password supposed to be empty? And did you check that SQL Server allows SQL Server authentication?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    4

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    I use cports.exe port browser utility and there is no service running on 1433 port. Indeed there is sqlserver service under port 2461, with IP-127. 0.0.1. There is the same service on another 0.0 ip but on port 2460. This error I got in case url COMPUTER-NAME\MSSQLSERVER:2461 and localhost:1433. So it seems does not matter as it is unreachable. If I delete username and password properties I got the same. This properties are void cause I use integrated security. I used COMPUTER-NAME\MSSQLSERVER4 as data source in connection string sharpdevelop with integrated security and db tables are visible without any need of tcp/ip enable. So windows authentification does not need user/pass maybe I need add ms server credentials. Maybe it is possible to use cmdline options to connect tcp/ip network to ms sql server?

  4. #4
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    4

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    When I open my ms sql server configuration manager I got such error: Cannot connect to wmi provides you do not have permission or the server is unreachable note that you can only manage sql server 2005 or later; specified module cannot be found. The same warning I get when I click on administrative tools-computer management - ms sql server configuration manager tab (despite there is two of them, the same ones), when before it WMI is void so probably not functional despite wmi service is running? To repair this issue accordingly to internet I need mssqlconfi...mof file. I found such one just in 2005 server version - 90 folder. Put in 100 folder, 2008 server version, and run mofcomp "this mof file" it succesfully tested but ms sql server confi manager is not workable with the same error. So maybe I could manually rewrite this *.mof file to settle to 2008 version as it is simple text file with mof extension? I told about that operation and file mofcomp sqlmgmproviderxps2up.mof
    Last edited by ark; 03-27-2017 at 07:05 PM.

  5. #5
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    4

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    Indeed the wmi snap-ip in Computer Management works. The properties context menu is active. So I do not know why there is such error. Could it be the error of jdbc itself? I would like to check the connection with ms sql server authentification - so I created simple login (when windows autgentificated) with the simpliest password. Indee when trying to login in server native mode I got error 18456 that Should be incorrect credentials. I also should note that some *.dll is needed when working with integrated windows authentification when working with java/jdbc. Maybe the reason is in it? Would anybody provide valid link for it?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    I would be very careful about trying random fixes, especially since you don't sound like a SQL Server admin.
    You are quite likely to muck up your installation.

    Since things like the config manager are having issues then I would not blame jdbc.
    Don't use JDBC to confirm your installation. Use the SQL Server tools to do that. If they are having problems then there is little point even trying to connect using JDBC.

    So, first step, is SQL Server installed correctly, and do the various tools work?
    Can you connect using those tools, including logging in and looking at the data in the database, for the account(s) you plan on using with JDBC?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    4

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    When I connect sharp develop (C# ide) to my database in ms sql server -- just creating some connection on database menu - the db tables and its structures are displayed. So no errors - despite I did not try to use retrieving of data with code -- several months ago I did it succesfully- despite probably not without issues. I probably need to provide java jdbc code for connection - it have @autowired controller, that has daoclass field.

  8. #8
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    4

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    Here is code of my controller and ao classes, maybe they are applied incorrectly:
    Java Code:
    @Controller
    public class InController {
    
       @Autowired  
       InDao dao;//will inject dao from xml file       
    
    	
       @RequestMapping(value = "/inn", method = RequestMethod.GET)
       public ModelAndView in() {
          return new ModelAndView("inn", "command", new Inn());
       }
       
       @RequestMapping(value = "/addInn", method = RequestMethod.POST)
       public String addInn( @Valid @ModelAttribute("command") Inn inn,
       BindingResult result,
       ModelMap model) {
          model.addAttribute("suma", input.getSuma());
          model.addAttribute("prof", input.getProf());
          model.addAttribute("ddate", input.getDdate());
          if (result.hasErrors()) {
    			return "inn";
    		} else {
    			try {
    			dao.save(inn);
    			    }
    			catch (Exception e) {inn.setStatus(e.toString());
    			model.addAttribute("status", input.getStatus());
    			}
    			return "inn";
    		}
       }
    }
    
    
    @@@
    public class InDao {  
    JdbcTemplate template;  
      
    public void setTemplate(JdbcTemplate template) {  
        this.template = template;  
    }
    
    public int save(Inn p){
    	
        String sql="INSERT INTO Profit("+p.getProf()+", Date) VALUES ("+p.getSuma()+","+p.getDdate()+")";  
        p.setStatus("Profit Added");
        return template.update(sql);   
        }
    }
    Last edited by ark; 03-28-2017 at 08:14 PM.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    I can only suggest going through MSDN for how-to's on setting up your version of SQL Server for use with JDBC and Windows Authentication.
    They will be the authority on this.

    One thing.
    That SQL should really be binding the variables, especially if one of them is a date. I can imagine that query failing.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    4

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    You should probably mean conversion but no binding. I am aware of it. So it is additional question -- what conversion tool I need use -- if I want to insert in format dd-MM-yyyy in c# code (I early inserted in such format, as well concatenated with hh:mm:ss in some rows/records). Should datetimeformattes class and simpleclassformat class produce just formatted strings not date/datetime format? If one of this class use such format "yyyy-MM-dd" -- should it drive the runtime error when inserting in the field the format dd-MM-yyyy? There is such special class as sql.Date class that has special method but it is probably not overloaded. Relating msdn I have read indeed there is mention in the internet that I need some *.dll for windows authentification? Would you provide list of files in 100\Shared folder of ms sql server I would compare with my ones.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    No, I mean binding.
    Java Code:
    template.update(sql, p.getSuma(), p.getDdate());
    This assumes both the column ("Date" is not a good name for a table column due to its similarity to a datatype) and the value returned by getDdate() are Dates.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    Don't rely on random internet pages.
    When I had issues with SQL Server (and the last time I had to set one up from scratch was a long time ago) MSDN had enough topics to sort it out.

    For example, have you been through this page, especially this part on integrated authentication?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #13
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    4

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    I have already found these and similar pages. Indeed I cannot find such file as sqljdbc_auth.dll or valid Microsoft JDBC Driver for SQL Server (that probably include this dll).
    There is such bad situation that almost all microsoft (msdn) pages are not displayed by this mesage in my Mozilla browser, so I need use google cache -- cache:https://docs.microsoft.com/en-us/sql...connection-url -- to see such pages.
    What about Date -- it is simple name of column -- not value (ddate is named there). Anyway these code was modified from c# code, that worked (asp.net, wpf ...)

  14. #14
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    4

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    This link java - dll missing in JDBC - Stack Overflow tells and provide link for such ddl and tells about some path for such dll? I found sqljdbc_auth.dll here http://en.osdn.jp/projects/sfnet_dos...jdbc_auth.dll/
    Indeed I cannot check it know. So maybe really I need fully install microsoft jdbc driver, not just jdbc.jar.

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    Quote Originally Posted by ark View Post
    Indeed I cannot find such file as sqljdbc_auth.dll or valid Microsoft JDBC Driver for SQL Server (that probably include this dll).
    There was a link at the top of that very page saying "Download JDBC Driver".
    Clicking that takes you here.
    And, as you say, there is the dll you are looking for, as one of the files for the driver.

    There is absolutely no need to go to anywhere other than Microsoft and, if you do, then you run the huge risk of downloading virus-ware.

    Since DATE is a SQL datatype it is generally not advised to use it as a column name, for clarity.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  16. #16
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    4

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    I will check but probably not today. Anyway it would be fine to get *.mof sql server file from 2008 server maybe at least the text. Maybe it is the same as my present 2005 one? I would just compare its text lines - about hundreds ones or so. Maybe the tcp/ip is launched for ms sql server. And about my spring mvc. It was difficult to import sample one - i needed to copy files manually. Then I resolved the need for validation jar enough along. Then now - jdbc error... There is such issue in spring that I created one class for mapping profits and expenditures. But due to validation I need to split it two ones. Can I block some fields of class against validation on runtime (in my code)? Moreover then I need 2 classes with just 2 date fields and one array field for retrieving the result from db. There is also interest could I use some db @annotation for class fields in my app such as @column without using modelmap? Main profit columnname is selected on runtime.

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    You're going to need to break these issues down.
    That's too much to cover in a single thread.
    It's all over the place.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    4

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    I have a few time for it now. But I have extracted and copied sqljdbc_auth.dll to System32 and Spring MVC lib folder but get the same error:
    "org.springframework.jdbc.CannotGetJdbcConnectionE xception: Could not get JDBC Connection; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port."
    If there is some no permissions for ms sql server -- but ASP.NET C# application succesfully connects to MS SQL server 2008 database. So I do not think it needs permisions just for ecclipse/jdbc.
    Have got any suggestions for that time?
    Last edited by ark; 04-17-2017 at 04:57 PM.

  19. #19
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    4

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    Can I do this things without ms sql server configuration manager that does not opens, but management studio works:
    java - JDBC connection failed, error: TCP/IP connection to host failed - Stack Overflow

  20. #20
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    4

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    I have repaired the ms server configuration manager -- indeed the tcp/ip connections is enabled so after
    launching after it nothing happened and the same error. I did not even suppose what it could be?
    Even worse after the restart of PC the management studio and ms sql main services cannot be launched as repair was not complete due to the few free space. So even in absence of this ms sql service -- the same error that sql server was not launhed and tcp/ip connection is not able.
    So maybe the reason is that MS server was not conneted to eclipse from the very beginning.
    I have checked all roles and logins -- db_reads, db_writes ...
    Here is my configuration servlet files and it did not even get error due to the presence of username and password (they should be void) that should not be valid:
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
    Index of /schema/mvc
    http://www.springframework.org/schem...spring-mvc.xsd
    Index of /schema/beans
    http://www.springframework.org/schem...ring-beans.xsd
    Index of /schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="tp"/>
    <mvc:annotation-driven />

    <bean class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
    </bean>

    <bean id="ds" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDrive r" />
    <property name="url" value="jdbc:sqlserver://localhost" />
    <property name="username" value="qa" />
    <property name="password" value="1" />
    </bean>

    <bean id="jt" class="org.springframework.jdbc.core.JdbcTemplate" >
    <property name="dataSource" ref="ds" />
    </bean>

    <bean id="dao" class="tp.InputDao">
    <property name="template" ref="jt" />
    </bean>

    </beans>

    I also woyuld like to know how I rwepair ms server 2008 not fully but just partially as during reair I got whole set of features -- I jsut need services, management studio and othe core components. Due to such moments my few free space disk PC does not allow copmlete reair?
    Or should I use new install with adding new features but all features is already installed.
    And after yesterdays repair -- main service could not be launched so management studio as well??

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 5
    Last Post: 09-25-2012, 05:36 PM
  2. Replies: 6
    Last Post: 02-24-2012, 04:22 PM
  3. Cannot connect to sqlserver 2008 with JDBC
    By alexander.s in forum JDBC
    Replies: 4
    Last Post: 03-13-2011, 12:02 AM
  4. SQL Server 2008 to NetBeans IDE 6.8
    By Wesley Chin in forum JDBC
    Replies: 0
    Last Post: 04-30-2010, 07:13 AM
  5. Connecting to SQL Server 2008 DB
    By Lyle in forum Eclipse
    Replies: 1
    Last Post: 02-22-2009, 04:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •